用Vb编程
1-100所有奇数,并求和,且没每行输出10个
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 "它们的和为:" & sum
End SubPrivate 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的和为" & sEnd Sub