下列程序用来计算1+2+…n,当和大于100时停止计算,请填空。 Private Sub Form_Click() Dim n as integer,s as integer,I as integer,k as integer s=0 k=0 n=

admin2010-11-20  24

问题 下列程序用来计算1+2+…n,当和大于100时停止计算,请填空。
Private Sub Form_Click()
Dim n as integer,s as integer,I as integer,k as integer
s=0
k=0
n=inputbox(″请输入n的值)
For i=1 to 100
    k=k+1
    s=s+I
【  】
Next i
Print s
End Sub

选项

答案if s>100 then exit for

解析 依题意,用变量S来记录1到n的累加和,当累加和S大于100时停止计算,故加入退出循环条件"if s>100 then exit for"
转载请注明原文地址:https://jikaoti.com/ti/XbO0FFFM
0

最新回复(0)