
Private Sub Command1_Click()
Dim i As Integer
Dim a As Integer, b As Integer, c As Integer
For i = 100 To 999
a = i \ 100 '求三位数的百位上的数
b = (i - a * 100) \ 10 '求三位数的十位上的数
c = i - a * 100 - b * 10 '求三位数的个位上的数
If a ^ 3 + b ^ 3 + c ^ 3 = i Then '判断是否为水仙花数
Print i '如果是水仙花数则输出.
End If
Next i
End Sub
用三重循环做:
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim s As Integer
For i = 1 To 9
For j = 0 To 9
For k = 0 To 9
s = i * 100 + j * 10 + k
If i ^ 3 + j ^ 3 + k ^ 3 = s Then
Print s
End If
Next k
Next j
Next i
End Sub
Option ExplicitPrivate Sub Command1_Click()
Dim a() As Integer
Dim i, j, n
ReDim a(9, 9)
For i = 1 To 8
Print Tab(25 - i * 2)
For j = 1 To i
a(i, 1) = 1
a(i, i) = 1
a(i + 1, j + 1) = a(i, j) + a(i, j + 1)
Print a(i, j)
Next j
Next i
End Sub
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)