求100以内奇数之和,但总是不行
private sub form_load()
show
dim i,x As Integer
for i=1 to 100 step 2 '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
x=x+i
print i,x
next i
end sub
private sub form_load()
show
dim i,x As Integer
for i=1 to 100 step 2 '我想从0--100应怎么写。如果1--100把step 2n+1行吗?
x=x+i
print i,x
next i
end sub
if i mod 2 then
x=x+i
print i,x
end if
next i
if i mod 2 then
x=x+i
print i,x
end if
next i
if i mod 2 then
x=x+i
print i,x
end if
next i
Show
Dim sum,x, BottomX, TopX As Integer
BottomX = 0'定义下限
TopX = 100'定义上限
x = BottomX'初始变量
Sum = 0
While x <= TopX And x >= BottomX
If x Mod 2 = 1 Then '判断满足条件
Sum = Sum + x
Debug.Print x, Sum
End If
x = x + 1 '计数加一
WendEnd Sub
(1+2n-1)*n/2 = n^2。