nsjd.net
当前位置:首页 >> vB编程计算1%2+3%4+5%6…+%n的值,n由用户输入 >>

vB编程计算1%2+3%4+5%6…+%n的值,n由用户输入

楼上的程序,个人认为有点小问题,修改如下: Private Sub Form_Click() Dim n As Integer Dim sum As Integer sum = 0 n = Val(InputBox("输入一个整数:")) sum = 0 For i = 1 To n '此处修改 sum = sum + (-1) ^ (i + 1) * i '此处修改 Next ...

新建一个工程,添加个命令按钮和一个文本框 代码如下: Private Sub Command1_Click() n = Val(Text1.Text) s = 0 '存结果 For i = 1 To n t = 1 '临时存积的变量 For j = 1 To i '计算阶乘 t = t * j Next j s = s + t Next i Print "结果为:"...

可以帮你 完成

没有错误,你用msgbox检查一下,结果是10100 Private Sub Form_Load() Dim s As Integer, n As Integer n = InputBox("请输入n的值") s = 0 For i = 1 To n s = s + i * 2 Next i MsgBox s End Sub

Private Sub Command1_Click() Print "第3题:"; Dim n As Integer, s As Double n = InputBox("n=", , 50) For i = 1 To n s = s + 1 / i Next i Print "Sum(" & n & ")="; Format(s, "0.00")End SubPrivate Sub Command2_Click() Print "第4题...

input “请输入最大值n" n s=0 for i=1 to n s=s+i next i print "S=";s

dim n as integer,s as long s=1 n=val(text1.text) for i=1 to n s=s*2 next text1.text="2的 " & n & " 次方的值:" & s

Private Sub Command1_Click() n = CInt(InputBox("求N!,请输入N的值:")) s = 1 For i = 2 To n s = s * i Next i MsgBox ("N!=" & s) End Sub

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

先输入一段代码,定义阶乘函数: Function f(n As Integer) As Long If n > 1 Then f = n * f(n - 1) Else f = 1 End IfEnd Function然后,再写一段代码,执行累加的运算,例如我要把结果在单击时输出在窗体上,且n取10时(当n取不同的值时可以...

网站首页 | 网站地图
All rights reserved Powered by www.nsjd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com