Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

Generation of Pythagorean Triples

Posted By: Simon Tembo     Category: C Programming     Views: 8014

A Pythagorean triple is a set of three integers a, b and c such that a^2+b^2=c^2. Such a triple can be produced from two integers m and n, using the Euclid formula.

To generate a list of Pythagorean triples m could be allowed to take values from its minimum possible value (2) up to some maximum value entered by the user. For each value of n from 1 up to m-1 the corresponding triple could then be evaluated and output. An algorithmic description for this is:

enter and validate a maximum value for m.
for each value of m from 2 to maximum do
   {
    for each value of n from 1 to m-1 do
       {
        evaluate and print a triple.
       }
   }

This description uses a for loop, a looping construct that repeats the loop statement as some control variable takes a sequence of values. Also note that one for loop is nested inside another, this is very common. From this description the following help to develop C program.

  
Share: 


Didn't find what you were looking for? Find more on Generation of Pythagorean Triples Or get search suggestion and latest updates.

Simon Tembo
Simon Tembo author of Generation of Pythagorean Triples is from Japan.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!