试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:普通

浙江省高中信息技术 高精度计算问题练习

小明编写了一个求真分数精确值的VB程序。程序运行时,在文本框Text1中输入被除数,在文本框Text2 中输入除数,并保证被除数小于除数,单击“计算”按钮Command1,在标签Label3中显示结果(最多计算到第20位)。程序运行界面如图所示。

(1)、实现上述功能的VB程序如下,请在划线处填入合适的代码。

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

(2)、运行程序,在文本框Text1中输入被除数1,在文本框Text2中输入除数3,单击“计算”按钮Command1,在标签Label3中显示的结果是
举一反三
返回首页

试题篮