第二章(22)程序的顺序结构
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
开始 输入一个三位数r的值
a= r \ 100
Private Sub ComBiblioteka Baiduand1_Click() Dim a as integer,b as integer, c as integer,r as integer
r=inputbox(“r=” ,“输入三 位数")
a= r \ 100
b= (r mod 100) \ 10
练 习:
(1)试编写一个程序,求平面中两点之间的距离 Private sub form_click() X1=inputbox(“坐标轴上的一个点坐标”) X2=inputbox (“坐标轴上的一个点坐标”) y1 =inputbox (“坐标轴上的一个点坐标”) y2=inputbox (“坐标轴上的一个点坐标”) S=sqr((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) Print s End sub
s = 2*(a * b + b * c + a * c) v=a*b*c
根据公式: s=2*(a*b+a*c+b*c)
根据公式:v=a*b*c
Print “表面积s=”; s
输出s
Print “体积v=”, v
输出v
结束
从键盘上输入一个三位整数,然后将它反向输出。例如 输入456,输出应是654。
private sub command1_click()
a=0.15m/s
t=2m=120s,
V0=40000/3600=(100/9)m/s
V=V0+a*t S=V0*t+a*t*t/2 Print “v=”;v,”s=”;s End sub
Private Sub Command1_Click() a = 0.15 t = 120 V0 = 400 / 36 v = V0 + a * t s = V0 * t + a * t * t / 2 Print "v="; v, "s="; s End Sub
Dim c as integer,r as integer r=inputbox(“r=” ,“输入三位数") a= r \ 100 b= (r mod 100) \ 10 c= r mod 10
r = c*100+ b*10 + a Print “反向三位数是”,r End Sub
实 践:
(1)试编写一个程序,实现输入圆的半径, 输出圆的周长和面积。
private subcommand1_click() PI=3.14 R=inputbox(“输入圆的半径”) M=2*PI*r S=PI*r*r Print “m=” ;m , “s=”;s End sub
(2)一列火车在某地时的速度为V0=40Km/h,现以加速度 a=0.15m/s2加速行驶,试编写一个程序,求2min后的 速度V和距开始点的距离S。
第2.2节 程序的顺序结构
(3)编写程序
Private Sub Command1_Click() Const s1 As Integer = 170, s2 As Integer = 144, s3 As Integer = 3, s4 As Integer = 36 Const s5 As Integer = 18, s6 As Integer = 12, s7 As Integer = 6, s8 As Integer = 6 Const s9 As Integer = 24, s10 As Integer = 10 Dim d1 As Single, d2 As Single, d3 As Single, d4 As Single, d5 As Single, d6 As Single, d7 As Single,d8 As Single, d9 As Single, d10 As Single Dim x As Single, y As Single d1 = Val(InputBox("请输入粮食的单价:")) d2 = Val(InputBox("请输入蔬菜的单价:")) d3 = Val(InputBox("请输入油脂类的单价:")) d4 = Val(InputBox("请输入薯类的单价:")) d5 = Val(InputBox("请输入肉类的单价:")) d6 = Val(InputBox("请输入干豆类的单价:")) d7 = Val(InputBox("请输入蛋类的单价:")) d8 = Val(InputBox("请输入鱼虾的单价:")) d9 = Val(InputBox("请输入乳类的单价:")) d10 = Val(InputBox("请输入水果的单价:")) x = s1 * d1 + s2 * d2 + s3 * d3 + s4 * d4 + s5 * d5 + s6 * d6 + s7 * d7 + s8 * d8 + s9 * d9 + s10 * d10 y = x / 0.6 Print "基本食品消费支出x="; x Print "总的生活消费支出y="; y
b= (r mod 100) \ 10
c= r mod 10
c= r mod 10
r = c*100+ b*10 + a
r = c*100+ b*10 + a
输出r的值 结束
Print “反向三位数是”;r End Sub
Private Sub Command1_Click()
Dim a as integer,b as integer
练一练:试编写一个程序,实现输入长方体的长、
宽、高,求长方体的表面积和体积。 开始
Dim a, b, c, s, v As Single
a = InputBox("长=", "输入")
输入a
b = InputBox("宽=", "输入")
输入b
c = InputBox("高=", "输入")
输入c
End Sub
(4)调试程序
Private Sub Command1_Click() Dim T As single A = 10 B = 20 T=A A=B B=T Print "A="; A, "B="; B End Sub
Private Sub Command1_Click() Dim T As single A = InputBox("A=", A) B = InputBox("B=", B) T=A A=B B=T Print "A="; A, "B="; B End Sub