作业帮 > 综合 > 作业

vb 输入10个整数,计算偶数个数 ,奇数和.

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/23 21:47:12
vb 输入10个整数,计算偶数个数 ,奇数和.
是先有一个框 输入数字范围,然后随机产生10个整数.
vb 输入10个整数,计算偶数个数 ,奇数和.
建立一个text1、一个command1,代码如下:
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox ("请先在框中输入数字的范围")
Exit Sub
End If
Dim A(10) As Integer, N As Integer
Dim I As Integer, Og As Integer, Jh As Integer
Form1.AutoRedraw = True
Form1.Cls
N = Val(Text1.Text)
Randomize
Print "输入的10个数是:";
For I = 1 To 10
A(I) = Int(Rnd * N) + 1
Print A(I);
If A(I) Mod 2 = 0 Then
Og = Og + 1
Else
Jh = Jh + A(I)
End If
Next
Print
Print "偶数个数是:"; Og
Print "奇数的和是:"; Jh
End Sub
已经运行过.
再问: 请问 我打错了 是 奇数的个数 和 偶数的个数,帮忙改一下 ,帮你加分
再答: 奇数的个数 和 偶数的个数,如下: Private Sub Command1_Click() If Not IsNumeric(Text1.Text) Then MsgBox ("请先在框中输入数字的范围") Exit Sub End If Dim A(10) As Integer, N As Integer Dim I As Integer, Jg As Integer, Og As Integer Form1.AutoRedraw = True Form1.Cls N = Val(Text1.Text) Randomize Print "输入的10个数是:"; For I = 1 To 10 A(I) = Int(Rnd * N) + 1 Print A(I); If A(I) Mod 2 = 0 Then Og = Og + 1 Else Jg = Jg + 1 End If Next Print Print "偶数个数是:"; Og Print "奇数个数是:"; Jg End Sub 也运行过了!