#include <stdioh>
void main(){
int a,b,c;
for(a=2;a<=48;a++)
for(b=a+1;b<=49;b++)
for(c=b+1;c<=50;c++)
if(aa+bb==cc)
printf("%-4d%-4d%-4d\n",a,b,c);
}
For[i = 1, i < 100, i++,
For[j = i, j < 100, j++,
For[k = j, k < 100, k++,
If[i^2 + j^2 == k^2,
Print[i, " ", j, " ", k];
]
]
]
]
直接复制进去,Shift+Enter ,结果为:
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
30 72 78
32 60 68
33 44 55
33 56 65
35 84 91
36 48 60
36 77 85
39 52 65
39 80 89
40 42 58
40 75 85
42 56 70
45 60 75
48 55 73
48 64 80
51 68 85
54 72 90
57 76 95
60 63 87
65 72 97
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Text1Text = ""
For i = 1 To 30
For j = i + 1 To 30
For k = j + 1 To 30
If ggs(i, j, k) = True Then
Text1Text = Text1Text & i & "," & j & "," & k & vbCrLf
End If
Next k
Next j
Next i
End Sub
Public Function ggs(a As Integer, b As Integer, c As Integer) As Boolean
If a a + b b = c c Then ggs = True
End Function
用for循环太慢了,看我的
>> a = 1:1000;
>> repa = repmat(a,1000,1);%复制向量成矩阵1000x1000
>> repb = repa';
>> c = sqrt(repa^2 + repb^2);
>> csign = (c == fix(c));%判别是否a^2+b^2=c^2
>> sum(csign(:))/2
ans =
1034
>> csign = tril(csign);%为避免重复,只取上半部分
>> tmp = [repa(csign),repb(csign),c(csign)];%三列,第一列为a,第二列为b,第三列为c
以上就是关于用c语言求解 输出1-50以内的所有勾股数全部的内容,包括:用c语言求解 输出1-50以内的所有勾股数、用Mathematica做:寻找100以内的勾股数。求程序设计及结果、用vb编写程序,输出30以内的勾股数组合,要输出到窗体的文本框中 并且要求使用子程序来实现等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)