level 1
vip香香菜
楼主
1. 编程在窗体上输出101~500之间的所有能被3或者7整除的奇数,按照一行5个的方式输出并最后符合要求的数的和。
解:代码为
Private Sub form_load()
Show
Dim n, sum As Integer
Print Spc(6); "101~500之间的所有能被3或者7整除的奇数,及各数的和"
i = 0
sum = 0
For n = 101 To 500 Step 2
If n Mod 3 = 0 Or n Mod 7 = 0 Then
sum = sum + n
i = i + 1
Print Spc(6); n;
If i Mod 5 = 0 Then
Print
End If
End If
Next n
Print Spc(7); "sum="; sum
End Sub
2. 在4个TextBox中输入4个大小不同的数,将它们从大到小排序后的结果用Msgbox函数输出。
解: 代码为
Private Sub Command1_Click()
Dim a!, b!, c!, d!
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = Val(Text4.Text)
If a <> b And b <> c And c <> d And a <> c And a <> d And b <> d Then
If a < b Then
t = a: a = b: b = t
End If
If a < c Then
t = a: a = c: c = t
End If
If b < c Then
t = b: b = c: c = t
End If
If d > a Then
t = d: d = a: a = t
End If
If d > b Then
t = d: d = b: b = t
End If
If d > c Then
t = d: d = c: c = t
End If
MsgBox "从大到小排序:" & a & "," & b & "," & c & "," & d
Else
MsgBox "有相同的数"
End If
2011年06月20日 05点06分
1
解:代码为
Private Sub form_load()
Show
Dim n, sum As Integer
Print Spc(6); "101~500之间的所有能被3或者7整除的奇数,及各数的和"
i = 0
sum = 0
For n = 101 To 500 Step 2
If n Mod 3 = 0 Or n Mod 7 = 0 Then
sum = sum + n
i = i + 1
Print Spc(6); n;
If i Mod 5 = 0 Then
End If
End If
Next n
Print Spc(7); "sum="; sum
End Sub
2. 在4个TextBox中输入4个大小不同的数,将它们从大到小排序后的结果用Msgbox函数输出。
解: 代码为
Private Sub Command1_Click()
Dim a!, b!, c!, d!
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = Val(Text4.Text)
If a <> b And b <> c And c <> d And a <> c And a <> d And b <> d Then
If a < b Then
t = a: a = b: b = t
End If
If a < c Then
t = a: a = c: c = t
End If
If b < c Then
t = b: b = c: c = t
End If
If d > a Then
t = d: d = a: a = t
End If
If d > b Then
t = d: d = b: b = t
End If
If d > c Then
t = d: d = c: c = t
End If
MsgBox "从大到小排序:" & a & "," & b & "," & c & "," & d
Else
MsgBox "有相同的数"
End If