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

VB编程问题

1、任意四位正整数的每位上数字取出来
2、将任意输入的三个数按照从大到小的顺序输出
3、从键盘接收一个数字,判断其是否小于零,等于零或大于零
4、求100以内的奇数和,并将结果显示在窗体上
5、求100以内的偶然和,并将结果显示在窗体上

6、任意生成10个两位正整数,将这10个数的和显示在Text1中,平均值显示在Text2中

答案:
'第一题答案
Private Sub Form_Click()
Dim n As Integer
Dim b As String
n = InputBox("请输入一个四位数:")
Print "输入的四位数是:" & n
b = CStr(n)
Print "第一位数是:" & Left(n, 1)
Print "第二位数是:" & Mid(n, 2, 1)
Print "第三位数是:" & Mid(n, 3, 1)
Print "第四位数是:" & Right(n, 1)
End Sub
'第二题答案
Private Sub Form_Click()
Dim a As Integer, b As Integer, c As Integer
a = InputBox("请输入一个整数:")
b = InputBox("请输入一个整数:")
c = InputBox("请输入一个整数:")
Print a, b, c
If a < b Then
d = a
a = b
b = d
End If
If a < c Then
d = a
a = c
c = d
End If
If b < c Then
d = b
b = c
c = d
End If
Print a, b, c
End Sub
'第三题答案
Private Sub Form_Click()
Dim n As Integer
n = InputBox("请输入一个整数:")
Select Case n
Case Is > 0
MsgBox "是个正数"
Case Is < 0
MsgBox "是个负数"
Case Is = 0
MsgBox "是零"
End Select
End Sub
'第四题答案
Private Sub Form_Click()
For i = 1 To 100 Step 2
s = s + i
Next i
Print "100以内的奇数和是:" & s
End Sub
'第五题答案
Private Sub Form_Click()
For i = 2 To 100 Step 2
s = s + i
Next i
Print "100以内的偶数和是:" & s
End Sub
'第六题答案
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Randomize Timer
For i = 1 To 10
a(i) = Int(Rnd * 90 + 10)
s = s + a(i)
Text1.Text = Text1.Text & a(i) & " "
Next i
Text2.Text = s / 10
End Sub
哥们,题目有点多,还没分

上一个:VB编程 属性
下一个:VB编程问题

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