四、程序填空(34%)(每空两分)
1 找出被3,5除,余数为1的最小的4个正整数。
Private sub command1_click( )
Dim countn ,n
Countn=0
----1----
Do
N=n+1
If x mod 3=1 and x mod 5=1 then
Print n
----2----
End if
Loop while ----3-----
End sub
2随机产生6位学生的分数(范围1-10),存放在数组a中,以每2分一个“*”显示(注:要求四舍五入求“*”,如31分要显示16个“*”。)如图:
Private sub command1_click( )
Dim a( 1 to 6)
For I=1 to 6
A( I)=----1----
Print ----2----
Next I
End sub
3下面程序是在用户按了Enter后将一个组合框(combo1)中没有的项目添加到组合框中.
Sub combo1_keypress(keyascii as integer)
Dim flag as Boolean
If ----1---- then
Flag=false
For I=0 to ----2----
If ----3---- then
Flag=true
Exit for
End if
Next
If flag=flase then
----4----
else
msgbox (“ 组合框中已有该项目”)
end if
end if
end sub
4键盘输入一个正整数(假定该数大于2),找出小于或等于该数的第一个素数。
Private sub command1_click()
Dim m, x, tag as Boolean
Tag=false
X=inputbox(“输入一个大于2的正整数”)
Do while ----1----
M=2: tag= true
Do while tag and m<int(sqr(x))
If x mod m=0 then tag=false else ----2----
Loop
If tag=----3---- then ----4----
Loop
Print x
End sub
5 该过程是将一个英文句子的每个单词的首字母都变成大写。从键盘上任意输入一条英文句子,将句子中的每个单词的首字母都变成大写.例如:输入I am a good student.要求输出I Am A Good Student.
Public Sub Uppersen()
Dim oldsen As String, newsen As String
Dim char As String, lastchar As String
Dim k As Integer, i As Integer
oldsen = InputBox("请输入英文句子:")
k = -------1--------
'以空格作为单词的界定,空格后的字母转换为大写字母
lastchar = ---------2--------
For i = 1 To k
char = ------3--------
If lastchar = " " Then
char = UCase(char)
End If
newsen = -----4-------
lastchar = char
Next i
Form1.Print "input:"; oldsen
Form1.Print "output:"; newsen
End Sub