RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
VB.NET写阶乘代码 vb10的阶乘的代码

用VB.NET编写一个程序 :编一求阶乘的函数f(n),主调程序求组合数的程序,分别调用f(n),用来计算组合数的值

Private Sub Command1_Click()

博野网站建设公司成都创新互联,博野网站设计制作,有大型网站制作公司丰富经验。已为博野1000多家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的博野做网站的公司定做!

Dim A, B, C

A = 10

B = 3

C = f(A) / (f(B) * f(A - B))

Print C

End Sub

Private Function f(n)

Dim I As Integer

f = 1

For I = 1 To n

f = f * I

Next I

End Function

怎么写vb的阶乘代码

1、For语句实现

Private Sub Command1_Click()

Dim s As Long, n As Integer, i As Integer

n = Val(Text1.Text)

s = 1

For i = 1 To n

  s = s * i

Next i

Label4.Caption = Str(s)

End Sub

2、Do While语句实现

Private Sub Command1_Click()

Dim s As Long, n As Integer, i As Integer

n = Val(Text1.Text)

s = 1

i = 1

Do While i = n

  s = s * i

  i = i + 1

Loop

Label4.Caption = Str(s)

End Sub

扩展资料:

1~10的阶乘的结果如下:

1!=1

2!=2*1=2

3!=3*2*1=6

4!=4*3*2*1=24

5!=5*4*3*2*1=120

6!=6*5*4*3*2*1=720

7!=7*6*5*4*3*2*1=5040

8!=8*7*6*5*4*3*2*1=40320

9!=9*8*7*6*5*4*3*2*1=362880

10!=10*9*8*7*6*5*4*3*2*1=3628800

VB.NET 怎样编写使用Do While 循环输出1-10的阶乘,我是新手请加上文字说明,呵呵,谢谢各位了!

首先在窗体上画两个控件:TextBox1和Button1

TextBox1用来输入需要计算那个数的阶乘

双击Button1进入输入代码,代码如下

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

Dim Factorial As Integer = 1 '定义一个变量用来记录阶乘的结果

Dim count As Integer '定义一个变量用来记录需要计算那个数的阶乘

Dim i As Integer = 1 '定义一个数用来循环

count = Int(Val(Me.TextBox1.Text)) '把TextBox1的值赋值给count

Do While i = count '下面开始计算阶乘

Factorial = Factorial * i '计算阶乘

i += 1 '自增1

Loop

MessageBox.Show(Int(Val(Me.TextBox1.Text)) "的阶乘是:" Factorial, "完成", MessageBoxButtons.OK) '弹出计算结果

Catch ex As Exception '出错提示

MessageBox.Show(Err.Description, "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub


本文名称:VB.NET写阶乘代码 vb10的阶乘的代码
标题网址:http://scyingshan.cn/article/dddjjjo.html