C Program to Check for Pythagorean Triplets

“Pythagorean triples” are integer solutions to the Pythagorean Theorem, a^2 + b^2 = c^2.

[cc lang=”c”]
#include
#include
main()
{
int s1,s2,hyp,ptriple=0;

printf(” Side1 —- side2 —- hypotenusn”);
for(s1=0;s1<=100;s1++) { for(s2=0;s2<=100;s2++) { for(hyp=1;hyp<=100;hyp++) { ptriple=(s1*s1)+(s2*s2); hyp=hyp*hyp; if(hyp==ptriple) { hyp=sqrt(hyp); printf("n%d ---- %d ---- %d ",s1,s2,hyp); } } } } } [/cc]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *