五笔打字通主页
12.编写程序求出100以内的所有勾股数,所谓勾股数是指满足条件a2+b2=c2(a≠b)的自然数。 ---- 课后答案
解,此题VB代码如下:
Private Sub Form_Click()
Dim a As Integer, b As Integer, c As Integer, j As Long
For a = 1 To 100
For b = 1 To 100
For c = 1 To 100
If a < b Then
If a * a + b * b = c * c Then
Print a; "*"; a; "+";
Print b; "*"; b; "=";
Print c; "*"; c; " ";
j = j + 1
If j Mod 2 = 0 Then Print'一行只输出2次数据,然后就换行
End If
End If
Next c
Next b
Next a
End Sub
此题程序运行效果图如下:
---- 新编Visual Basic程序设计教程 答案 陈斌 著
来源:济亨网
本文链接:https://wb98.com/post/157.html