我必須找到所有具有值「c」(其中c是斜邊)的畢達哥拉斯三元組,小於用戶輸入的整數值。我能夠做到這一點,但是我也必須打印哪個三元組具有最大的「c」值。如何打印具有最大斜邊的畢達哥拉斯三元組
# include <stdio.h>
int main()
{
int i=1, N, a, b, c;
printf("Please enter an integer number: ");
scanf("%d", &N);
for(c=1; c<N; c++)
{
for(b=1; b<c; b++)
{
for(a=1; a<b; a++)
{
if((a*a)+(b*b)==(c*c))
{
printf("\n%d.(%d,%d,%d)\n", i++, a, b, c);
}
}
}
}
printf("\nThere are %d triples which contain a c<N.\n\n", (i++)-1);
system("PAUSE");
return(0);
}
以上代碼的哪些部分不起作用?請明確點。 – 2014-10-01 02:32:42
您在最終的'printf'語句中不需要'i ++'。只需使用'我'。它不會對代碼產生任何影響,除非你在這個語句之後使用'i'的值,這就使得它更難以閱讀。 – 2014-10-01 02:41:50
代碼運行良好,我只是不知道該如何在代碼末尾打印句子「發現c值最大的三元組是(?,?,?)。換句話說,我不知道
the1whoknocks
2014-10-01 02:44:00