一些题目
Posted xbnl-bk-zm-2018
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一些题目相关的知识,希望对你有一定的参考价值。
数组A中存储了15个评委对某参赛歌手的评分,去掉一个最高分和一个最低分,求该选手的实际平均得分。(5.0分)
窗体顶端
我的答案
Private Sub Form_Click()
Dim i%, a(15) As Single, max!, min!, s%
For i = 0 To 14
a(i) = InputBox("")
Next i
max = a(0)
min = a(0)
For i = 0 To 14
If max < a(i) Then
max = a(i)
If min > a(i) Then
min = a(i)
End If
End If
Next i
For i = 0 To 14
s = s + a(i)
Next i
Print (s - max - min) / 13
End Sub
窗体底端
10
从键盘上输入两个数m和n,求两个数的最大公约数。(5.0分)
窗体顶端
我的答案
Public Function gcd(a As Integer, b As Integer)
If b = 0 Then
gcd = 1
End If
If a Mod b = 0 Then
gcd = b
Else
gcd = gcd(b, a Mod b)
End If
End Function
Private Sub Form_Click()
Dim m%, n%
m = InputBox("")
n = InputBox("")
Print gcd(m, n)
End Sub
窗体底端
11
税务部门征收所得税,规定如下: (1)全年应纳所得额在3 6000元内,税率3%; (2)全年应纳所得额在3 6000元至14 4000元内,超出3 6000元部分税率10%; (3)全年应纳所得额在14 4000元至30 0000元内,超出14 4000元部分税率20%; (4)全年应纳所得额在30 0000元至42 0000元内,超出30 0000元部分税率25%; (5)全年应纳所得额在42 0000元至66 0000元内,超出42 0000元部分税率30%;(5.0分)
窗体顶端
我的答案
Private Sub Form_Click()
Dim salary!, tax%
salary = InputBox("")
If salary <= 36000 Then
tax = salary * 0.03
ElseIf salary <= 144000 Then
tax = (salary - 36000) * 0.1 + 36000 * 0.03
ElseIf salary <= 300000 Then
tax = 36000 * 0.03 + (144000 - 36000) * 0.1 + (salary - 144000) * 0.2
ElseIf salary <= 420000 Then
tax = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (salary - 300000) * 0.25
ElseIf salary <= 660000 Then
tax = 36000 * 0.03 + (144000 - 36000) * 0.1 + (300000 - 144000) * 0.2 + (420000 - 300000) * 0.25 + (salary - 420000) * 0.3
End If
Print "所得税为:" & tax
End Sub
窗体底端
12
三色球问题。若一个口袋中放有12个球,其中3个红色的,3个白色的,6个黑色的,从中任意选择八个球,问
共有几种不同的颜色搭配?(5.0分)
窗体顶端
我的答案
Private Sub Form_Click()
Dim i%, j%, c%
For i = 1 To 3
For j = 1 To 3
For k = 1 To 6
If i + j + k = 8 Then
Print "红球:"; i; "白球:"; j; "黑球:"; k
c = c + 1
End If
Next k
Next j
Next i
Print "共有" & c & "种方案"
End Sub
窗体底端
13
从键盘上输入3个整数,输出其中的最大值、最小值和平均值。(5.0分)
窗体顶端
我的答案
Private Sub Form_Click()
Dim a%, b%, c%, max%, min%
a = InputBox("")
b = InputBox("")
c = InputBox("")
max = a
min = a
If (max < b) Then
max = b
End If
If (max < c) Then
max = c
End If
If (min > b) Then
min = b
End If
If (min > c) Then
min = c
End If
Print "最大值:" & max
Print "最小值:" & min
Print "平均值:" & (a + b + c) / 3
End Sub
窗体底端
14
输出[100,9999]区间的所有回文数,每行输出10项,分多行输出。要求使用Function过程进行回文数判断。(5.0分)
窗体顶端
我的答案
Public Function hws(a As Integer)
If StrReverse(a) = a Then
hws = 1
Else: hws = 0
End If
End Function
Private Sub form_Click()
Dim i%
For i = 100 To 9999
If hws(i) = 1 Then
Print i;
n = n + 1
If n Mod 10 = 0 Then Print
End If
Next i
End Sub
窗体底端
15
在一个一维数组中有相同元素,出现次数最多的元素称为众数。编程序在包含(10,5,0,-1,5,0,5,10,5,0)10个元素的数组找出众数并输出。 提示:用双重循环统计每个数出现的次数。(5.0分)
窗体顶端
我的答案
窗体底端
1
求1~100之间的所有质数,将质数的个数显示在窗体上,质数从小到大依次写入顺序文件 c:\dataout.txt 中,在划线处填上缺少的内容(5.0分)
窗体顶端
我的答案
Public Function susu(a As Integer)
Dim v As Boolean
v = False:
n = 2
Do While n <= Sqr(a) And v = False
If a Mod n = 0 Then
v = True
Else: n = n + 1
End If
Loop
If v = False Then
susu = 1
Else: susu = 0
End If
End Function
Private Sub Form_Click()
Dim i%, c%
c = 0
Open "C:\dataout.txt" For Output As #1
For i = 1 To 100
If susu(i) = 1 Then
Print #1, i;
End If
Next i
Close #1
End Sub
窗体底端
2
随机产生30个30~100之间的随机整数作为学生成绩,将成绩从大到小排序后存入顺序文件file1.txt中。(5.0分)
窗体顶端
我的答案
Public Function ff(a As Integer)
If a Mod 10 = (a Mod 1000) \ 100 Then
ff = 1
Else: ff = 0
End If
End Function
Private Sub Form_Click()
Dim grade(30) As Integer, t%
Open "file1.txt" For Output As #1
For i = 0 To 29
grade(i) = Int(Rnd * 71 + 30)
Next i
For i = 0 To 28
For J = i To 29
If grade(i) > grade(J) Then
t = grade(i)
grade(i) = grade(J)
grade(J) = t
End If
Next J
Next i
For i = 0 To 29
Print #1, grade(i);
Next i
Close #1
End Sub
窗体底端
3
将1000-2000之间的素数找出来,写入到顺序文件c:\ss.txt中。(5.0分)
窗体顶端
我的答案
Public Function susu(a As Integer)
Dim v As Boolean
v = False:
n = 2
Do While n <= Sqr(a) And v = False
If a Mod n = 0 Then
v = True
Else: n = n + 1
End If
Loop
If v = False Then
susu = 1
Else: susu = 0
End If
End Function
Private Sub Form_Click()
Dim i%, c%
c = 0
Open "d:\ss.txt" For Output As #1
For i = 1000 To 2000
If susu(i) = 1 Then
Print #1, i;
End If
Next i
Close #1
End Sub
窗体底端
4
挑出1000~9999之间所有个位和百位为奇数的数据存入顺序文件file1.txt中。(5.0分)
窗体顶端
我的答案
Public Function ff(a As Integer)
If a Mod 10 = (a Mod 1000) \ 100 Then
ff = 1
Else: ff = 0
End If
End Function
Private Sub Form_Click()
Dim i%, c%
c = 0
Open "file1.txt" For Output As #1
For i = 1000 To 9999
If ff(i) = 1 Then
Print #1, i;
End If
Next i
Close #1
End Sub
以上是关于一些题目的主要内容,如果未能解决你的问题,请参考以下文章