如何在Visual Basic中解决这个三角问题?我不知道我是否做对了

发布于 2025-02-01 17:12:17 字数 1142 浏览 2 评论 0原文

制作一个程序,该程序读取一个正整数不超过10的程序,并打印出数字的三角形,如下所示:
如果读数为5,则应打印:

1

22

333

4444

55555

该程序必须重读另一个数字,直到输入的数字大于10。

我尝试过 this ,但我不知道它是否正确:

    Dim num As Integer
    Dim i As Integer
    num = InputBox(" enter a number")
    For i = 1 To num Step 1
        If i = 1 Then

            ListBox1.Items.Add(1)

        ElseIf i = 2 Then
            ListBox1.Items.Add(22)

        ElseIf i = 3 Then
            ListBox1.Items.Add(333)
        ElseIf i = 4 Then
            ListBox1.Items.Add(4444)
        ElseIf i = 5 Then
            ListBox1.Items.Add(55555)
        ElseIf i = 6 Then
            ListBox1.Items.Add(666666)

        ElseIf i = 7 Then
            ListBox1.Items.Add(7777777)
        ElseIf i = 8 Then
            ListBox1.Items.Add(88888888)
        ElseIf i = 9 Then
            ListBox1.Items.Add(999999999)
        ElseIf i = 10 Then
            ListBox1.Items.Add(1010101010101010101010)

        End If
    Next

Make a program that reads a positive integer no greater than 10, and prints a triangle of numbers as follows:
If the number read were 5, then it should print:

1

22

333

4444

55555

The program must reread another number until the number entered is greater than 10.

I have tried this, but I don't know if it is correct:

    Dim num As Integer
    Dim i As Integer
    num = InputBox(" enter a number")
    For i = 1 To num Step 1
        If i = 1 Then

            ListBox1.Items.Add(1)

        ElseIf i = 2 Then
            ListBox1.Items.Add(22)

        ElseIf i = 3 Then
            ListBox1.Items.Add(333)
        ElseIf i = 4 Then
            ListBox1.Items.Add(4444)
        ElseIf i = 5 Then
            ListBox1.Items.Add(55555)
        ElseIf i = 6 Then
            ListBox1.Items.Add(666666)

        ElseIf i = 7 Then
            ListBox1.Items.Add(7777777)
        ElseIf i = 8 Then
            ListBox1.Items.Add(88888888)
        ElseIf i = 9 Then
            ListBox1.Items.Add(999999999)
        ElseIf i = 10 Then
            ListBox1.Items.Add(1010101010101010101010)

        End If
    Next

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文