189 8069 5689

vb点虐 阶乘 vb中阶乘的程序设计

程序高手来1~10的阶乘。用VB.NET

Public Class Form1

目前创新互联已为千余家的企业提供了网站建设、域名、雅安服务器托管绵阳服务器托管、企业网站设计、卫滨网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

Inherits System.Windows.Forms.Form#Region " Windows 窗体设计器生成的代码 " Public Sub New()

MyBase.New() '该调用是 Windows 窗体设计器所必需的。

InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub 'Windows 窗体设计器所必需的

Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程。

'不要使用代码编辑器修改它。

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Name = "Form1"

Me.Text = "Form1" End Sub#End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim s As String

Dim i As Integer, f As Long

For i = 0 To 10

f = Factor(i)

s = s i "!=" f vbNewLine

Next i

MsgBox(s)

End Sub

Function Factor(ByVal n As Integer) As Long

End Function

End Class

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自定义过程,求阶乘!

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

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

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


标题名称:vb点虐 阶乘 vb中阶乘的程序设计
分享路径:http://cdxtjz.cn/article/ddidcco.html

其他资讯