VB程序设计第四版实验题求解

VB程序设计第四版实验题求解,第1张

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 Explicit

Private 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

Print

Next i

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11094759.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-13
下一篇2023-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存