回覆列表
  • 1 # 藍風24

    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

  • 中秋節和大豐收的關聯?
  • 一個人沒有理想追求就能知足常樂嗎?