Three positive integers (a, b, c) with a<b<c are called a Pythagorean triple if the sum of the square of a and the square of b is equal to the square of c. Write a program that prints all Pythagorean triples (one in a line) with a, b, and c all smaller than 1000, as well the total number of such triples in the end. Arrays are not allowed to appear in your code. Hint: user nested loops (Can you make your code as efficient as possible? But this is not required). Submit only your code in a PDF file. Write in C programming.
#include<stdio.h> int main(){ int a,b,c,n=1000; for(a=1;a<=n;a++){ for(b=a+1;b<=n;b++){ for(c=b+1;c<=n;c++){ if(a*a+b*b==c*c){ printf("%d, %d, %d\n", a,b,c); } } } } return 0; }
Get Answers For Free
Most questions answered within 1 hours.