Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how to wirte a C program of finding pythagorean triples of which its 3 sides are

ID: 3621506 • Letter: H

Question

how to wirte a C program of finding pythagorean triples of which its 3 sides are under 500 by using all three kinds of loop?And it sould show both (3,4,5) and (4,3,5) I did wrote one but it didn't work.Can somebody tell me which part of it was wrong?

#include <stdio.h>
#include <stdlib.h>
int x,y,z,a,b;
x = 1;
y = 1;
do{
while(++y <= 500){
for(z = 1;z <= 500;++z){
a = z*z;
b = x*x + y*y;
if(b == a)
printf("%3d %3d %3d ",x,y,z);
}
}
}while(++x <= 500);
system("pause");

return 0;
}

Explanation / Answer

please rate - thanks

y=1 was in the wrong place

#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y,z,a,b;
x = 1;
do{
    y = 1;
   while(++y <= 500){
      for(z = 1;z <= 500;++z){
          a = z*z;
          b = x*x + y*y;
          if(b == a)
                  printf("%3d %3d %3d ",x,y,z);
          }
      }
}while(++x <= 500);
system("pause");

return 0;
}