程序设计汇总
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
程序设计题目汇总
36、购物计费:某商场为了促销而实行购物打折,在商场购物500元以上(不包括500元),超过部分实行八折优惠。已知某顾客购物按未打折计共花费了898元,编程计算顾客实际应付的金额。A表示顾客的购物金额,x表示顾客应该实际付给商场的金额。请将程序缺失部分补充完整。
Function func()
Dim a As Single, x As Single
a = 898
If a <= 500 Then
_______________________
Else
x = 500 + ( a – 500) * 0.8
End If
func = "应付金额x=" & x
End Function
答案:x = a
39、计算房租费,70平方以下(包括70)每平方4元,如果超过70平方则超过部分每平方6元。程序中变量m为平方数,变量n为房租费。
Function func()
Dim m As Integer, n As Integer
m = 128
If m <= 70 Then
n = 4 * m
________________
n = 4 * 70 + 6 * (m – 70)
End If
func = "房租费n=" & n
End Function
答案:Else
40、已知正方形的边长A是8,下列程序的功能是计算正方形的周长L。请将程序缺失部分补充完整。Function func()
Dim A As Single
Dim L As Single
A = 8
L = _________________
Func = "正方形的周长" & L
End Function
答案:4*A
37、判断奇偶性,如果是偶数让x为0,如果是奇数让x为1
Function func()
Dim a As Integer, x As Integer
If a / 2 = Int( a / 2) Then
x = 0
Else
x = _________________
End If
End Function
答案:1
38、从键盘输入圆的半径R,输出圆的周长L和面积S,补充完整下列程序段。
Dim R As Single, L As Single, S As Single
________________= InputBox("输入半径R")
L = 2 * 3.14 * R
S = 3.14 * R * R
Print "圆的周长是";L
Print "圆的面积是";S
答案:R
40、计算旅客的行李费,收费标准为:20千克以下(包括20千克)不收费,超过20千克的部分每千克收20元。X表示行李重量,Y表示行李费。补充完整下列程序段。
Dim X As Single, Y As Single
X = InputBox("输入行李重量")
If _________________Then
Y = 0
Else
Y = 20 * (X - 20)
End If
Print "行李费=";Y
答案:x <= 20
36、将a、b的值互换后输出
Function func()
Dim a As Single
Dim b As Single
Dim c As Single
a = 3
b = 4
_______________
a = b
b = t
func = "a=" & a & " b=" & b
End Function
答案:t = a
37、编写一元二次方程X^2+3X+2=0的求解程序,要求能够判断方程是否有根,如果没有根则给出相应的提示信息。请将下列程序补充完整。
Function func()
Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single
Dim x1 As Single
Dim x2 As Single
b = 3
c = 2
d = b * b - 4 * a * c
if d>=0 Then
x1 = _____________________
x2 = (-b - Sqr(d)) / (2 * a)
func = "x1="&x1&" x2="&x2
Else
func = "无实根"
End If
End Function
答案:x = (-b + Sqr(d)) / (2 * a)
37、该程序功能是求S=10+20+30+……+100,请将空格补完整实现前述功能。Function func()
Dim I As Integer, s As Integer
s = 0
For i= 10 To 100 Step 10
s = _______________________
Next I
func = s
End Function
答案:s+i
36、该程序的功能是求S=1+3+5+……+99。请将程序缺失部分补充完整。Function func()
Dim i As Integer, s As Integer
s = 0
For i = 1 To ________________ Step 2
s = s + i
Next i
func = s
End Function
答案:99
37、该程序功能是求S=10+20+30+……+100,请将空格补完整实现前述功能。Function func()
Dim i As Integer, s As Integer
s = 0
For i= 10 To 100 Step ______________
s = s + i
Next i
func = s
End Function
答案:10
38、完成如下算法设计:
该程序功能是求S=2+4+6+ (100)