- 9
- 0
- 约8.47千字
- 约 11页
- 2017-05-12 发布于河南
- 举报
vb第四章选择结构和循环结构编程题
第四章编程题
1.查询分数题
Private Sub Form_Load()
x = Val(InputBox(请输入分数, 输入, 0))
Select Case x
Case Is 0
Label1.Caption = 输入有误
Case Is 100
Label1.Caption = 输入有误
Case Is = 90
Label1.Caption = 优秀
Case Is = 80
Label1.Caption = 良好
Case Is = 70
Label1.Caption = 一般
Case Is = 60
Label1.Caption = 及格
Case Is 60
Label1.Caption = 不及格
End Select
End Sub
2.求最大公约数题
Private Sub Command1_Click()
Dim m As Integer, n As Integer, p As Integer
m = Val(Text1.Text)
n = Val(Text2.Text)
If m 0 Or n 0 Then
MsgBox 数据错误!
End
End If
p = m Mod n
Do While p o
m = n
n = p
p = m Mod n
Loop
Text3.Text = n
End Sub
2.1最小公倍数
Private Sub Command1_Click()
Dim m As Integer, n As Integer, p As Integer, t As Integer
m = Val(Text1.Text)
n = Val(Text2.Text)
t = m * n
If m 0 Or n 0 Then
MsgBox 数据错误!
End
End If
If m = 0 Or n = 0 Then
Text3.Text = 0
Else
Do
p = m Mod n
If p = 0 Then
Exit Do
End If
m = n
n = p
Loop Until False
Text3.Text = t / n
End If
End Sub
九九乘法表
Private Sub Command1_Click()
Dim I As Integer, J As Integer, M As Integer, s As String
For I = 1 To 9
s =
For J = 1 To I
M = I * J
s = s J * I = M
Next J
List1.AddItem s
Next I
End Sub
4.求ABCD—CDC=ABC题
Private Sub Command1_Click()
For a = 1 To 9: For b = 0 To 9
For c = 1 To 9: For d = 0 To 9
x = a * 1000 + b * 100 + 10 * c + d
y = c * 100 + d * 10 + c
z = a * 100 + b * 10 + c
If x - y = z Then
Print x; y; z
End If
Next
Next
Next
Next
End Sub
求前100项和,平均数题
Private Sub Form_click()
n = 1: s = 0
Do While n = 100
s = s + n
n = n + 1
Loop
Print s, n - 1, s / (n - 1), s * (n - 1)
End Sub
6.输入10个数找出正数,负数,零的个数
Private Sub Command1_Click()
Dim i, t, x1, x2, x3 As Integer
For i = 1 To 10
t = Val(InputBox(请输入第 i 个数:, 显示, 0))
If t 0 Then
x1 = x1 + 1
ElseIf t 0 Then
x2 = x2 + 1
Else
x3 = x3 + 1
End If
Next
Print 正数的个数: x1
Print 负数的个数: x2
Print 零的个数: x3
您可能关注的文档
- MFC编程总结各种控件使用说明.doc
- MFC编程讲义.doc
- MFC菜单设计.doc
- Microsoft Excel 提供了多个对话框工作表控件.doc
- Microsoft Office 最小化功能区.doc
- MFC标准控件使用.doc
- MLCad软件入门介绍.doc
- mt4 编程入门.doc
- MiniGUI在SKyEye0.8.6上的成功移植.doc
- MT4编程.doc
- 小区绿化施工协议书.docx
- 墙面施工协议书.docx
- 1 古诗二首(课件)--2025-2026学年统编版语文二年级下册.pptx
- (2026春新版)部编版八年级道德与法治下册《3.1《公民基本权利》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《4.3《依法履行义务》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.2《按劳分配为主体、多种分配方式并存》PPT课件.pptx
- (2026春新版)部编版八年级道德与法治下册《6.1《公有制为主体、多种所有制经济共同发展》PPT课件.pptx
- 初三教学管理交流发言稿.docx
- 小学生课外阅读总结.docx
- 餐饮门店夜经济运营的社会责任报告(夜间贡献)撰写流程试题库及答案.doc
原创力文档

文档评论(0)