① 用vb:输入10个整数,求出它们的总和与积,并打印其中既能被5整除又能被3整除的数
Private Sub Command1_Click()
Dim i, a(10), sum, ji
ji = 1
For i = 1 To 10
a(i) = Int(Val(InputBox("输入第" & i & "个数")))
Print a(i);
sum = sum + a(i)
ji = ji * a(i)
Next
Print vbCrLf & "总和=" & sum
Print "积=" & ji
Print "能被3和5整除的有:"
For i = 1 To 10
If a(i) Mod 5 + a(i) Mod 3 = 0 Then Print a(i);
Next
Print
End Sub
② VB语言实现10个数和
做完了,不用任何控件,代码如下:
Dim M(6) As Byte, H(6) As Byte
Dim G(3) As Byte
Dim I As Byte, J As Byte, Hj As Integer
Const N = 10, X = 6, Y = 33
Private Sub Form_Click()
Cls
For I = 0 To X
M(I) = I: H(I) = 0
Next
Hj = 0
I = 1
Call ZuHe
Print "共有以上"; Hj; "个结果符合题目要求。"
Print "单击窗口重做一遍。"
Print: Print "双击窗体退出程序......"
End Sub
Sub ZuHe()
Do While M(I) <= N - X + I
H(I) = H(I - 1) + M(I)
If I = X Then
For J = 1 To 3
G(J) = 0
Next
For J = 1 To X
If M(J) >= 1 And M(J) <= 3 Or M(J) = 6 Then G(1) = G(1) + 1
If M(J) = 1 Or M(J) = 2 Or M(J) >= 7 And M(J) <= 10 Then G(2) = G(2) + 1
If M(J) = 5 Or M(J) = 6 Or M(J) = 9 Then G(3) = G(3) + 1
Next
If (H(I) > 30 And H(I) < 34) And (G(1) > 0 And G(1) < 3) And (G(2) > 0 And G(2) < 4) And (G(3) > 0 And G(3) < 3) Then
Hj = Hj + 1
Print Hj;
For J = 1 To X
If J > 1 Then Print "-";
Print M(J);
Next
Print
End If
ElseIf H(I) < Y Then
I = I + 1
M(I) = M(I - 1) + 1
Call ZuHe
I = I - 1
End If
M(I) = M(I) + 1
DoEvents
Loop
End Sub
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_Load()
Form1.AutoRedraw = True
Form1.Caption = "S.T.S.-数字求和"
Form1.Width = 10000
Form1.Height = 5000
Print "本程序不用任何控件,点击窗口即可运行,结果将显示在窗口内。双击窗体退出程序。"
Print: Print: Print "单击窗口继续......"
End Sub
已经运行过。如果有什么问题请再留言。祝你学习进步!
③ vb程序:随机产生10个1-100之间(不包含1和100)的整数,并求出这10个数的和,请写出程序代
DimSUMAsinterger
DimiAsinterger
DimVAsinterger
PrivateSubCommand1_Click()
SUM=0
Fori=1To10
Randomize
V=int(1+98*Rnd)
SUM=SUM+V
MsgBox"10个随机数的和为:"&SUM,32
next
EndSub
将楼上的改一下,应该更好
楼上的第2、3行有问题
④ vb题 随机生成10个两位整数,求出他们的总和及平均数
PrivateSubCommand1_Click()
Dimtt(100),s(10),temp1,temp2,temp3,i
Randomize'随机,不使用时,rnd()函数是有规律的
Fori=1To100
tt(i)=i'用tt数组存放100个数,不直接用S数组是为了避免出现重复的数字
Nexti
Fori=1To10
1s(i)=tt(Int(Rnd()*99+10))'循环10次得到数组s,存放10个随机数
Ifs(i)<>""Then'如果得到的s数组值不为空
temp3=temp3+s(i)'把10个数相加
tt(s(i))=""'把tt数组已取出的值赋予空值
Else
GoTo1'如果取出的值为空,则跳转到1,重新取值
EndIf
Nexti
temp3=temp3/10'用10个数相加的和除以10,求出平均数
'弹出对话框,显示10个随机数
MsgBoxs(1)&Chr(13)&s(2)&Chr(13)&s(3)&Chr(13)&s(4)_
&Chr(13)&s(5)&Chr(13)&s(6)&Chr(13)_
&s(7)&Chr(13)&s(8)&Chr(13)&s(9)&Chr(13)&s(10)
temp2=100'temp2用于存放最小值,需设置一个最大值,否则temp2无法得到数据
Fori=1To10
Ifs(i)>=temp1Thentemp1=s(i)'如果当前值大于temp1,则temp1取当前值
Ifs(i)<=temp2Thentemp2=s(i)'如果当前值小于temp2,则temp2取当前值
Nexti
Fori=1To10'求总和
Sum=Sum+s(i)
Nexti
'弹出对话框,显示最大值,最小值,平均值,总和
MsgBox"最大值:"&temp1&Chr(13)&"最小值:"&temp2&Chr(13)&"平均值:"&temp3&Chr(13)&"总和:"&Sum
EndSub
⑤ vb 编程 求用inputbox函数输入的10个数的和数和连乘积
一楼的程序有问题,应该是这样的
Private Sub Form_DblClick()
Dim g As Single
Dim i As Integer
Dim j As Double
g = 0
j = 1
For i = 1 To 10
k = InputBox("Input your number", "Inout")
g = g + k
j = j * k
Next i
Print "和=" & g
Print "连乘积=" & j
End Sub
⑥ VB用数组结构编写程序,输入10个整数,统计奇数之和及偶数之和,谢谢
Private Sub Form_Click()
Dim A(1 to 10) as Long
Dim Jc as long ,Oc as Long
For i=1 to 10
A(I)=Val(InputBox("请输入第" & i & "个数据"))
If A(i) mod 2 =0 then oc=oc+A(I)
If A(i) mod 2 =1 then jc=jc+A(i)
Next
Print "奇数的和为:" & jC
Print "偶数的和为:" & Oc
End Sub
⑦ 用VB做一个程序,输入十个数,累加求和。用While-Wend的方式。谢啦!
...
sum=0
count=0
while count<=10
count=count+1
x=val(inputbox("输入第" & count & "个数" )
sum=sum+x
wend
msgbox "十个数的总和是" & sum
...
⑧ vb高手进~求任意输入十个正整数的和,代码!~!
Private Function sum(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Integer, ByVal h As Integer, ByVal j As Integer, ByVal k As Integer, ByVal l As Integer) As Long
sum = a + b + c + d + e + f + g + h + j + k + l
End Function
这是函数
你只要调用就是了
方法. . 变量(对像)=sum(数,数,数,数,数,数,数,数,数,数)