我写了下面的代码,但它给出了重复的输出。如 3,4,5 和 4,5,3 和 5,4,3。它显示相同的三元组。我怎样才能防止这种情况?
#include <stdio.h>
int main(void){
int side1=1;
int side2=1;
int hypotenus=1;
int till;
int count=0;
printf("Till what number do you want to find triplets?");
scanf("%d",&till);
for(side1=1;side1<=till;side1++){
for(side2=1;side2<=till;side2++){
for(hypotenus=1;hypotenus<=till;hypotenus++){
if(hypotenus*hypotenus==side1*side1+side2*side2){
count++;
printf("%5d %5d %5d is a triple \n",side1,side2,hypotenus);
}
}
}
}
printf("\n");
printf("%d triplets found.",count);
return 0;
}