VB编程:计算1!+3!+5!+7!+9!用循环结构怎么做?要详细过程
3个回答
展开全部
这里只能给出伪代码了,VB没学过,假设是算到n的阶乘。
sum = 0;
fac = 1;
for (i = 1; i <= n; i++) {
fac = fac * i;
if (i mod 2 == 0) continue;
sum = sum + fac;
}
sum = 0;
fac = 1;
for (i = 1; i <= n; i++) {
fac = fac * i;
if (i mod 2 == 0) continue;
sum = sum + fac;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-11-10
展开全部
vb的代码如下:计算到9!
Dim i, j As Integer
Dim s1 As Double
Dim s2 As Double
s2 = 0
For i = 1 To 9 Step 2 '1,3,5,7,9
s1 = 1
For j = 1 To i '1,3,5,7,9 !
s1 = s1 * j
Next j
s2 = s2 + s1
Next i
MsgBox s2 '输出结果 368047
Dim i, j As Integer
Dim s1 As Double
Dim s2 As Double
s2 = 0
For i = 1 To 9 Step 2 '1,3,5,7,9
s1 = 1
For j = 1 To i '1,3,5,7,9 !
s1 = s1 * j
Next j
s2 = s2 + s1
Next i
MsgBox s2 '输出结果 368047
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim x As Long, y As Long
x = 1
For i = 1 To 9 Step 2
For j = 1 To i
x = x * j
Next
y = y + x
x = 1
Next
MsgBox y
End Sub
Dim i As Integer, j As Integer
Dim x As Long, y As Long
x = 1
For i = 1 To 9 Step 2
For j = 1 To i
x = x * j
Next
y = y + x
x = 1
Next
MsgBox y
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询