tfsf.net
当前位置:首页>>关于vb编程求n的阶乘的资料>>

vb编程求n的阶乘

这难道不是等差数列求和吗……编程对数学还是有要求的呢更新:恕我愚钝XD,我还没学到这个.好久没玩vb了,我用python写一个,给你提供基本的计算思路.第一个方法:def calcSingleFactorial(no): tmp = 1 for x in range(2,no+1): tmp = tmp*x

Dim s As Double, n As Integer n = Val(InputBox("请输入n值,不要太大哦,否则出错")) s = 1 Do While n > 1 s = s * n n = n - 1 Loop MsgBox "这个数的阶乘为" & s

用vb求1到n的阶乘和的程序:1. 自己编写函数代码:private function jiec(byval n as integer) as long dim i as integer dim fac as long fac = 1 for i = 1 to n fac = fac * i next i jiec = facend function2. 在需要求阶乘的地方,调用该函数:例如:dim y as longy = jiec(10) '求阶乘(10)将用10调用上面的自定义函数,返回10的阶乘

用vb求1到n的阶乘和的程序:1. 自己编写函数代码:Private Function jieC(Byval n As Integer) As Long Dim i As Integer Dim Fac As Long Fac = 1 For i = 1 To n Fac = Fac * i Next i jieC = Fac End Function2. 在需要求阶乘的地方,调用该函数:例如:Dim y As Long y = jieC(10) '求阶乘(10)将用10调用上面的自定义函数,返回10的阶乘

Private Sub Command1_Click() Dim fac As Double, n As Integer, i As Integer fac = 1 n = CInt(InputBox("请输入要计算阶乘的数N:")) If n < 0 Then MsgBox "N不能小于0!": Exit Sub For i = 2 To n fac = fac * i Next i MsgBox n & "!=" & fac End Sub

Private Sub Command1_Click()Dim m As Integer, n As Integerm = Int(InputBox("输入第一个整数"))n = Int(InputBox("输入第一个整数"))If m >= n Thencmn = jiecheng(m) / (jiecheng(n) * jiecheng(m - n))Print cmnElse: MsgBox "输入数据有错"

Private Sub Command1_Click()Dim n As Integern = InputBox("请输入一个正整数:")Print Fac(n)End SubPrivate Function Fac(m) As Long'' '请不要删除该行,只在下一行中填空'For k = 2 To mFac = Fac * kNext kEnd Function

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