1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdio.h>
#include<math.h>
int main(){
int range=0,
PTN=0, // counter
a=1, b=2, c=3,
max_a=0,max_b=0,max_c=0;
printf("Please enter a positive integer as the range: ");
scanf("%d",&range);
for(c=1 ; c < range ; c++){
for(b=1; b < c; b++){
for(a=1; a < b; a++){
if( (pow(a,2) + pow(b,2) )== pow(c,2) ){
printf("\n(%d,%d,%d)", a,b,c);
PTN++; //counter
if(max_a < a) max_a = a;
if(max_b < b) max_b = b;
if(max_c < c) max_c = c;
}
}
a=1;
}
b=1;
}
printf("\nThere were %d Pythagorean Triples of whom (%d,%d,%d) is the greatest.\n",PTN,max_a,max_b,max_c);
return 0;
}
|