求解1^3+3^3+5^3+…………(2n-1)^3=? 用VB循环结构程序编写的代码
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 16:17:58
求解1^3+3^3+5^3+…………(2n-1)^3=? 用VB循环结构程序编写的代码
求解1^3+3^3+5^3+…………(2n-1)^3=? 用VB循环结构程序编写的代码
求解1^3+3^3+5^3+…………(2n-1)^3=? 用VB循环结构程序编写的代码
那个推荐答案是错的,他没有累加,所以得出的结果是最后那个数的计算值
Private Sub Form_Click()
Dim i As Long,n As Long,s As Double
n = Val(InputBox("请输入n值"))
For i = 1 To n
s = s + (2 * i - 1) ^ 3
Next
MsgBox "计算结果为" & s
End Sub
同求
请先学会化简后在编程计算,那样效率会高很多.
Option Explicit
Private Function nsancf(n As Long) As Double
Dim djg As Double
For n = 1 To 2 * n - 1 Step 2
djg = n * n * n
Next n
nsancf = djg
End...
全部展开
Option Explicit
Private Function nsancf(n As Long) As Double
Dim djg As Double
For n = 1 To 2 * n - 1 Step 2
djg = n * n * n
Next n
nsancf = djg
End Function
Private Sub Form_Click()
Dim d As Double, n As Long
n = InputBox("请输入数字")
Print Str(nsancf(n))
End Sub
收起