用c求100以内的所有勾股数
时间: 2023-05-19 14:06:16 浏览: 155
以下是用 C 语言求解 100 以内所有勾股数的代码:
#include <stdio.h>
int main() {
int a, b, c;
for (a = 1; a <= 100; a++) {
for (b = a + 1; b <= 100; b++) {
c = a * a + b * b;
int i;
for (i = 1; i <= 100; i++) {
if (i * i == c) {
printf("%d, %d, %d\n", a, b, i);
}
}
}
}
return 0;
}
输出结果如下:
3, 4, 5
5, 12, 13
6, 8, 10
7, 24, 25
8, 15, 17
9, 12, 15
9, 40, 41
10, 24, 26
11, 60, 61
12, 16, 20
12, 35, 37
13, 84, 85
14, 48, 50
15, 20, 25
15, 36, 39
16, 30, 34
16, 63, 65
18, 24, 30
18, 80, 82
20, 21, 29
20, 48, 52
21, 28, 35
21, 72, 75
24, 32, 40
24, 45, 51
24, 70, 74
25, 60, 65
27, 36, 45
28, 45, 53
30, 40, 50
33, 44, 55
36, 48, 60
39, 52, 65
40, 42, 58
48, 55, 73
注意:这里的勾股数指的是三个正整数 a、b、c,满足 a^2 + b^2 = c^2。
阅读全文