当前位置:编程学习 > VB >>

用Vb编程

1-100所有奇数,并求和,且没每行输出10个
答案:Private Sub Form_Click()
    Dim i As Integer, sum As Integer, n As Integer
    For i = 1 To 100 Step 2
        n = n + 1
        If n Mod 10 = 0 Then
            Print i
        Else
            Print i,
        End If
        sum = sum + i
    Next
    MsgBox "总和为:" & sum
End Sub
Private Sub Form_Load()
Dim sum As Integer
Me.AutoRedraw = True
For i = 1 To 99 Step 2
   sum = sum + i
   Print i;
   If (i + 1) Mod 20 = 0 Then Print
Next i
Print
Print "它们的和为:" & sum
End Sub

Private Sub Command1_Click()

For i = 0 To 100
Print i;
If i Mod 10 = 9 Then Print
Sum = Sum + i
Next
    Dim j As Integer, s As Integer
    Do While j <= 100
        s = s + j
        j = j + 1
    Loop
    Print "1-100的和为" & s

End Sub

上一个:请问vb编程
下一个:电脑VB编程

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,