① 用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(數,數,數,數,數,數,數,數,數,數)