VisualBasic程序设计—实验报告册-参考答案 下载本文

Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() Dim n, sum As Integer n = Val(InputBox(\sum = jsh(n)

Print \End Sub

Public Function jsh(n) As Integer Dim i, s, t As Integer s = 0 t = 1

For i = 1 To n t = t * i s = s + t Next i jsh = s

End Function

VERSION 5.00

Begin VB.Form Form1

AutoRedraw = -1 'True Caption = \ ClientHeight = 3555 ClientLeft = 60 ClientTop = 450 ClientWidth = 5760 LinkTopic = \ ScaleHeight = 3555 ScaleWidth = 5760

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495 Left = 3600 TabIndex = 0 Top = 2280 Width = 1215 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True Attribute VB_Exposed = False

Private Sub Command1_Click() Dim n, flag As Integer

n = Val(InputBox(\输入任意一个数\sushu n, flag

Print n; \的标志是\End Sub

Public Sub sushu(n, flag) flag = 1

For i = 2 To n - 1

If n Mod i = 0 Then flag = 0: Exit For Next i End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 4305 ClientLeft = 60 ClientTop = 450 ClientWidth = 6945 BeginProperty Font

Name = \黑体\ Size = 26.25 Charset = 134 Weight = 700

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

LinkTopic = \ ScaleHeight = 4305 ScaleWidth = 6945

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 615 Left = 3960 TabIndex = 0 Top = 3360

Width = 2775 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() n = InputBox(\任意输入一个数\

If hws(n) = True Then Print n; \是\不是\End Sub

Function hws(x) As Boolean Print x hws = True

For i = 1 To Len(x) \\ 2

If Mid(x, i, 1) <> Mid(x, Len(x) + 1 - i, 1) Then hws = False Exit For End If Next i

End Function VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 3660 ClientLeft = 60 ClientTop = 450 ClientWidth = 5895 BeginProperty Font

Name = \黑体\ Size = 24 Charset = 134 Weight = 700

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

LinkTopic = \ ScaleHeight = 3660 ScaleWidth = 5895

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command2 Caption = \过程形式\

BeginProperty Font

Name = \宋体\ Size = 18 Charset = 134 Weight = 700

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Height = 615 Left = 3600 TabIndex = 1 Top = 2760 Width = 1935 End

Begin VB.CommandButton Command1 Caption = \函数形式\ BeginProperty Font

Name = \宋体\ Size = 18 Charset = 134 Weight = 700

Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty

Height = 615 Left = 600 TabIndex = 0 Top = 2760 Width = 1935 End End

Attribute VB_Name = \

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False

Rem 利用函数过程求 n!/(m!.(n-m)!) Function fact2(x) t = 1

For i = 1 To x t = t * i Next i

fact2 = t End Function

Private Sub Command1_Click() m = Val(InputBox(\输入 N\ n = Val(InputBox(\输入 M\ s1 = fact2(n) s2 = fact2(m) s3 = fact2(n - m)

Print \函数法结果为\End Sub

Rem 利用子程序过程求 n!/(m!.(n-m)!) Sub fact1(ByVal x As Integer, t) t = 1

For i = 1 To x t = t * i Next i End Sub

Private Sub Command2_Click() m = Val(InputBox(\ n = Val(InputBox(\ fact1 n, s1 fact1 m, s2

fact1 n - m, s3

Print \子过程结果\End Sub

VERSION 5.00

Begin VB.Form Form1

Caption = \ ClientHeight = 3090 ClientLeft = 60 ClientTop = 450 ClientWidth = 4680 LinkTopic = \ ScaleHeight = 3090 ScaleWidth = 4680

StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command1 Caption = \ Height = 495