- #1
MathematicalPhysicist
Gold Member
- 4,699
- 371
i was asked to write a code that search for pythogrean triples, my fault in my code is that i don't know where to write the codnition that a<b<c, cause as of now runs duplicates of pyhtogrean's triples.
here's the code:
any hints as to where to place this condition?
here's the code:
Code:
main()
{
int n,max,a,b,c;
printf("insert the degree you wish to check for n-th pythogrean triplets\n");
scanf("%d", &n);
printf("insert the maximal number you want to check for\n");
scanf("%d", &max);
if(max>2){
for(a=1;a<=max;a++)
{
for(b=2;b<=max;b++)
{
for(c=3;c<=max;c++)
{
if((pow(a,n)+pow(b,n)==pow(c,n))&& gcd(a,b)==1){
f++;
printf("the triplet is: %d, %d, %d \n", a,b,c);
}
}
}
}
}