当前位置:IT认证>BASIC题库

问题:[填空题]

[填空题] 下列程序用来计算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+1 (13) Next i Print s End Sub

  

参考答案:

ifs>100thenexitfor

  参考解析

依题意,用变量s来记录1到n的累加和,当累加和s大于100时停止计算,故加入退出循环条件“ifs>100thenexitfor”。

微信端