题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 高精度计算问题练习
Dim a(1 To 20) As Integer, b(1 To 20) As Integer
‘判断循环节
Function Judge(position As Integer) As Boolean
Dim i As Integer
For i = 1 To position - 1
If b(i) =Then Judge = False : Exit Function
Next i
Judge = True
End Function
Private Sub Command1_Click()
Dim m As Integer, n As Integer, x As Integer, i As Integer
Dim flag As Boolean, st As String
m = Val(Text1.Text):n = Val(Text2.Text)
st = Str(m) + “/” + Str(n) + “=”
st = st + “0.”
i = 1: x = 1: flag = True
b(1) = m
m = m * 10
Do While i <= 20 And flag = True
a(i)=
If a(i) > 0 Then
x = x + 1
b(x) = m Mod n
m = b(x) * 10
Else
m = m * 10
End If
flag = Judge(x)
If b(x) =0 And x <> 0 Then flag = False
st =
Loop
Label3.Caption = st
End Sub
排序前 |
86 |
71 |
5 |
41 |
81 |
79 |
37 |
89 |
排序后 |
5 |
37 |
41 |
71 |
79 |
89 |
86 |
81 |
实现上述功能的VB代码如下,但加框处有错,请改正。
Const n=8
Dim a(1 To n)As Integer
Private Sub Commandl_Click()
Dim i As Integer,j As Integer,k As Integer,t As Integer
Dim flag As Boolean
'读取一组正整数,存储在数组a中,代码略
For i= 1 To n-1
'(1)
If IsPrime(a(k))Then flag = True Else flag = False
For j = i + 1 To n
If IsPrime(a(j)) Then
If Then '(2)
k=j
flag = True
End If
End If
Next j
If k <> i Then
t=a(k):a(k)= a(i):a(i)= t
End If
If Not flag Then Exit For 'Exit For表示退出循环
Next i
'依次输出排序后的数据。代码略
End Sub
Function IsPrime(m As Integer)As Boolean
'本函数判断m是不是素数:是素数返回值为True,不是素数返回值为False
'代码略
End Function
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#}
试题篮