VB程序编写中求1^2+2^2+3^2+…+10^2的和,下面的程序为什么输入结果一直是1,程序代码中哪里错了
PrivateSubForm_Click()DimsAsIntegerDimiAsIntegers=0i=1Ifi<=10Thens=s+i*ii=i+1EndIfPri...
Private Sub Form_Click()
Dim s As Integer
Dim i As Integer
s = 0
i = 1
If i <= 10 Then
s = s + i * i
i = i + 1
End If
Print s
End Sub 展开
Dim s As Integer
Dim i As Integer
s = 0
i = 1
If i <= 10 Then
s = s + i * i
i = i + 1
End If
Print s
End Sub 展开
4个回答
展开全部
if 不是循环语句
If i <= 10 Then
s = s + i * i
i = i + 1
End If
改成
While i <= 10
s = s + i * i
i = i + 1
Wend
If i <= 10 Then
s = s + i * i
i = i + 1
End If
改成
While i <= 10
s = s + i * i
i = i + 1
Wend
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有循环呀 改成这样
Private Sub Form_Click()
Dim s As Integer
Dim i As Integer
s = 0
i=1
do while i <= 10
s = s + i * i
i = i + 1
loop
Print s
End Sub
Private Sub Form_Click()
Dim s As Integer
Dim i As Integer
s = 0
i=1
do while i <= 10
s = s + i * i
i = i + 1
loop
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'要用一个小小的循环体才能实现呢
Private Sub Form_Click()
Dim s As Integer
Dim i As Integer
s = 0
For i = 1 To 10
s = s + i * i
Next
Print s
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将“s = 0
i = 1
If i <= 10 Then
s = s + i * i
i = i + 1
End If”
改为“
s=0
for i=1 to 10 step 1
s=s+1*i
next i
”
i = 1
If i <= 10 Then
s = s + i * i
i = i + 1
End If”
改为“
s=0
for i=1 to 10 step 1
s=s+1*i
next i
”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询