怎么在VB中求和
怎么在VB中求和
你的问题不够具体…那么我给你一个例子,你参考下:
Private Sub Form_Load()
Dim a(1 To 50)
Show
For i=1 To 50
a(i)=101*RND
sum=sum+a(i)
Next i
Print sum
End Sub
以上希望能给你帮助,求和主要是用到循环,可以用For和Do。
vb求和语言
Private Sub Command1_Click()
a = Val(Text1)
s = Len(a)
Sum = 0
For i = 1 To s
Sum = Sum + a Mod 10
a = a \ 10
Next i
Text2 = Str(Sum)
End Sub
Private Sub Command2_Click()
Text1 = ""
Text1.SetFocus
Text2 = ""
End Sub
Private Sub Command3_Click()
End
End Sub
VB求和的函数是什么
把 text3.text=text1.text+text2.text 这句改成下面这句就可以了,
val是提取text中的数字,这样才可以加减运算,只有变成数字,才能加减运算。
text3.text=val(text1.text)+ val(text2.text)
如图下图,不懂可以追问我
VB正确几种求和方法
答案选择B
A
sum=0
for i=1 to 10
sum=sum+1
next i
print sum
每次都是sum+1,循环10次后sum的值是10,没有进行1+2+3。。d的运算
B
sum=0
i=1
do while i<=10
sum=sum+i
i=i+1
loop
print sum
第一次sum=0+1
第二次sum=sum+2,因为i=i+1增加了
.
C
sum=sum+1做的是sum=sum+1,相当于每次循环1+1+1+1的了,不是1+2+3+4
D
do
sum=sum+i
i=i+1
loop until i<10
这里的条件是loop until,不是while
当初i<10满足条件后就停止循环了。
vb怎样编写求和∑程序?
private function msum(a as integer,b as integer)
s=0
for k=a to b
s=s+f(k)
next
msum=s
end function
private function f(k as integer)
... '提问未给出f(k)的具体算式,这里以省略号代替
end function
用 vb 做 100以内质数求和 的程序
在窗体上添加个按钮
Private Sub Command1_Click()
Dim i As Integer, s As Integer, j As Integer, l As Integer
For i = 2 To 100
l = 0
For j = 2 To i - 1
If i Mod j = 0 Then l = 1
Next j
If l 1 Then s = s + i
Next i
Print "100以内质数和为" & s
End Sub
斐波那契数列如何用VB求和
斐波那契数列的发明者,是意大利数学家列昂纳多·斐波那契.
斐波那契数列指的是这样一个数列:1、1、2、3、5、8、13、21、……
下面是前1000项斐波那契数列的和的VB代码:
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim S As Long
Dim i As Integer
a = 1
b = 1
S = 2
For i = 3 To 1000
c = a + b
S = S + c
a = b
b = c
Next i
Print S
End Sub
如何用VB求和
中间的算法如下:
Dim sum As Integer
n = 99 '你输入的最大数
i = 1
sum = 0
Do Until i > n
sum = sum + i
i = i + 1
Loop
'求和到此为止,下面的是求素数
k = 1
Do Until k > n
For j = 1 To k / 2
If k Mod j = 0 And j 1 Then
Exit For
End If
Next j
If j > k / 2 And k 2 Then
MsgBox k
End If
k = k + 1
Loop
VB程序求和
程序本身有2处错误:
1.变量 s 不能申明为 Integer,应为 Single
2.语句 s = ② 将改变 s 的值,导致无法得到正确结果
因此,不改变程序结构永远得不到正确结果
完整序列为:
1/1 + 1/2 + 2/3 + 3/5 + 5/8 + 8/13 +
13/21 + 21/34 + 34/55 + 55/89
Private Sub Command1_Click()
Dim s As Single
Dim a As Integer
Dim b As Integer
Dim k As Integer
Dim J As Integer
s = 0
a = 1
b = 1
For k = 1 To 10 '第 7 项是 21/34
s = s + a / b
J = a
a = b
b = b + J
Next
MsgBox s
Print s
End Sub
怎样用vb求和
双击窗体
输入
Private Sub Form_Load()
Dim a, b As Single
For a = 1 To 100 Step 1
b = b + 1 / a
Next
MsgBox (b)
End Sub
怎么在VB中求和:等您坐沙发呢!