Private Sub Command1_Click()
在安远等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都做网站 网站设计制作按需搭建网站,公司网站建设,企业网站建设,成都品牌网站建设,营销型网站,外贸网站建设,安远网站建设费用合理。
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
Private Function a%(b)
s = 1
For i = 1 To b
s = s * i
Next i
a = s
End Function
Private Sub Form_activate()
For i = 1 To 10
n = n + a(i)
Next i
Print n
End Sub
首先在窗体上画两个控件: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