
编程计算1-2+3-4+5-6+。。。。+n的值,其中n由文本框输入(用vb编写谢谢,最好程序简明)
4个回答
展开全部
Dim Sum As long
Dim n As long
Dim i As long
Sum = 0
n = Clng(Text1.Text)
For i = 1 To n
If i Mod 2 = 1 Then Sum = Sum + i Else Sum = Sum - i
Next i
Dim n As long
Dim i As long
Sum = 0
n = Clng(Text1.Text)
For i = 1 To n
If i Mod 2 = 1 Then Sum = Sum + i Else Sum = Sum - i
Next i
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub Command1_Click()
Dim i%, n%, m%, k%
i = Val(Text1)
n = 1
For m = 1 To i
k = k + m * n
n = -n
Next m
Print "1+2+3+...+" & i & "=" & k
End Sub
Private Sub Form_Load()
Text1 = ""
End Sub
加一个命令按钮
Private Sub Command1_Click()
Dim i%, n%, m%, k%
i = Val(Text1)
n = 1
For m = 1 To i
k = k + m * n
n = -n
Next m
Print "1+2+3+...+" & i & "=" & k
End Sub
Private Sub Form_Load()
Text1 = ""
End Sub
加一个命令按钮
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim i as long,sum as long
sum=0
for i=1 to n
sum=sum+iif(i mod 2 = 0, -i ,i)
next i
msgbox sum
或者
sum=-(i\2)
if i mod 2 then sum=sum+i
sum=0
for i=1 to n
sum=sum+iif(i mod 2 = 0, -i ,i)
next i
msgbox sum
或者
sum=-(i\2)
if i mod 2 then sum=sum+i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private sub command1_click()
if text1<>""then
n=val(text1)
for i=1 to n
s=s+i
next i
msgbox str(n)
end if
end sub
if text1<>""then
n=val(text1)
for i=1 to n
s=s+i
next i
msgbox str(n)
end if
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询