Pages

Simple C Language Program to Printf Pythagorean Triples

A simple C language program to print all Pythagorean Triples from 0 to 1000, using loops and if-else statements.

Pythagorean Triples

Pythagorean Triples are a set of three numbers such that the sum of the squares of two numbers is equal to the square of the third numbers. If you ever paid attention to geometry at school (unlike me :p), then you must have come across the Pythagoras's Law, which states that the square of the hypotenuse of a right triangle is equal to the sum of the squares of the base and perpendicular.
If A,B and C are Pythagorean Triples, then they should obey the following relation:

A2 + B2 = C2   or   B2 + C2 = A2   or   C2 + A2 = B2 
 
#include <stdio.h>
#include <math.h>
int main(void)
{
 int a,b,c;
 for(a=0;a<=1000;a++)
 {
  for(b=0;b<=1000;b++)
  {
   for(c=0;c<=1000;c++)
   {
    if(pow(a,2)+pow(b,2)==pow(c,2))
     {
     printf("%d + %d = %d\n",a,b,c);
     }
   }
  }
 }
return 0;
}
From the Programmer
If you find any error or glitch in the code, you have a better way to do it or just wanna say Hi! then feel free to drop me a comment and I'll be happiest to reply. :)