describe:

若三个正整数a、b、c,其中a<=b<=c,满足a^2+b^2=c^2,其中^表示上标,称这三个数为“勾股数”,例如:3、4、5是勾股数。
编程输出不大于n的所有勾股数。

code:

#include <stdio.h>

#include <math.h>

int main()
{
int a;
double c;

scanf("%d",&a);
for (int i = 1; i < a; i++) {
for (int j = i; j < a; j++) {
if ((c = sqrt(pow(i, 2) + pow(j, 2))) == (int)c&&c <= a)  /*利用条件判定实现赋值,将i^2+j^2开方,若结果为整数且小于输入的数,则输出*/
printf("%d %d %d\n", i, j, (int)c);
}
}
return 0;

}

result:

例如输入100

输出无重复勾股数——巧用条件语句

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-08-04
  • 2021-08-05
猜你喜欢
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2022-12-23
相关资源
相似解决方案