佳伶 發問時間: 電腦與網際網路程式設計 · 1 0 年前

程式設計問題C((急))

(1)

*****

空****

空空***

空空空**

空空空空*

讓程式能印出這個形狀~

(2)

讓程式能算出組合問題

C (n取m)

2 個解答

評分
  • Kathy
    Lv 4
    1 0 年前
    最佳解答

    (1)

    Private Sub Command1_Click()

    For N = 1 To 5

    For M = 1 To N - 1

    Print " ";

    Next

    For M = 6 - N To 1 Step -1

    Print "*";

    Next

    Print

    Next

    End Sub

    (2)

    Private Sub Command2_Click()

    Dim intSum As Double

    Dim intSum1 As Double

    Dim intSum2 As Double

    Dim intSum3 As Double

    Dim i, j, k, x, y, z As Integer

    x = Val(InputBox("請輸入N取M中的N數值"))

    y = Val(InputBox("請輸入N取M中的M數值"))

    intSum = 1

    For i = 1 To x

    intSum = intSum * i

    Next i

    intSum1 = 1

    For j = 1 To y

    intSum1 = intSum1 * j

    Next j

    intSum2 = 1

    For k = 1 To x - y

    intSum2 = intSum2 * k

    Next k

    intSum3 = intSum / (intSum1 * intSum2)

    Print intSum3

    End Sub

    2009-12-09 12:03:27 補充:

    如果第一題沒法印出題目所要求的,問題出在 Print " "; 這裡要印兩格的空格,回答時HTML把它變成了只空一格!

    參考資料: , me
  • Nona
    Lv 6
    1 0 年前

    提供另一種寫法

    Me.FontName = "細明體"

    For N = 5 To 1 Step -1

    Print Space(5 - N) & String(N, "*")

    Next

還有問題?馬上發問,尋求解答。