n =357859604
Do While n>0
c=n Mod 10
If c>5 Then c=5
count (c) = count(c) + 1
n=n\10
Loop
数组元素count (0)到count (9)的初始值均为0,执行该程序段后,则count (5)的值为( )
s = "0123456789"
For i=1 To 5
s=Mid(s,1,k-1)+Mid(s,k+1)
Next i
上述程序段中方框处可选语句为:
①k=Int(Rnd*10)+1
②k=Int(Rnd*Len(s)+1)
③d(k)=i
④d(i) = Val(Mid(s,k,1))
则方框处语句依次是( )
c= 0
For i=1 To 7
k=i
For j=i+1 To 8
If a(j) <= a(k) Then k= j
Next j
If a(i)<>a(k) And i<>k Then
t=a(i):a(i)=a(k):a(k)=t
c=c+1
End If
Next i
数组元素a(1)到a(8)的值依次为“54,12,23,12,7,12,78,23”,执行该程序段后,变量c的值是( )
i =1:j= 8:n= 0:key= 83
Do While i<=j
n=n+1
m=(i+j)\2
If key > a(2 * m) Then j=m-1 Else i=m+1
Loop
Text1。Text = Str(a(2 * j - 1))
数组元素a(1)到a(16)的值依次为“6,90,3,85,5,83,2,83,4,83,8,80,7,77,1,70”,奇数位存储序号,偶数位存储成绩。执行该程序段后,下列说法正确的是( )
根据.上述要求设计VB程序,功能如下:在窗体加载时,读取木块长度和厚度数据,并显示在列表框List1中,单击“排序”按钮实现木块排序,结果显示在列表框List2中,程序运行界面如图b所示。
Const n = 10
Dim cd(1 To n) As Single, hd(1 To n) As Single
Private Sub Form_ Load()
'通过数据库读取n根木块的长度数据存储到cd数组,厚度数据存储到hd数组,并将数据显示在列表框List1中,代码略
End Sub
Private Sub Com1_Click()
Dim L As Integer, R As Integer
Dim min As Integer
Dim i As Integer, j As Integer
Dim t1 As Single, t2 As Single
For i=1 To n-1
min=i
For j=i+1 To n
If Then min= j
Next j
R=min
'实现区间内木块的整体翻转
Do While L<R
t1 = cd(L): cd(L) = cd(R): cd(R) = t1
t2 = hd(L): hd(L) = hd(R): hd(R) = t2
L=L+1
Loop
Next i
List2. AddItem"长度(cm)"+""+"厚度(cm)"
For i =1 To n
List2. AddItem Str(cd(i)) +"" + Str(hd(i))
Next i
End Sub
类型 |
计算公式 |
结果 |
||
有限小数 |
格式 |
a. b |
(a*x+b)/x |
|
示例 |
3. 14 |
(3*10^ 2+14)/10 2 |
157/50 |
|
纯循环小数 |
格式 |
a. (b) |
(a*(x-1)+b)/(x-1) |
|
示例 |
3. (14) |
(3*(10^ 2-1)+14)/(10^2-1) |
311/99 |
|
混循环小数 |
格式 |
a.b(c) |
(a*(t-1)*x+ (b*t+c-b))/((t-1)*x) |
|
示例 |
3. 14(159) |
(3*(10 3-1)*10 2+(14*10 3+159-14))/(10^ 3-1)*10^2) |
20923/6660 |
|
说明: ()内的数字串表示循环节 x=10 Len(b) t=10' Len(c) |
程序运行时,在文本框Text1中输入小数,单击“转化”按钮,输出对应的分数,界面如图所示。
Private Sub Command1_ Click()
Dim s As String, xS As String, zS As String
Dim fz As Long, fm As Long
Dim i As Integer
Dim x As Integer, y As Integer
s = Text1.Text
i=1
Do While Mid(s, i, 1) <> "."
i=i+1
Loop
zs =
xs=Mid(s, i+1)
If not(f(xs)) Then
fm = power (Len(xs))
fz = val(zs) * fm + vas (xs)
Else
If Mid(xs, 1, 1) = "(" Then
xs = Mid(xs, 2, Len(xs) - 2)
fm = power(Len(xs)) - 1
fz = Val(zs) * fm + Val(xs) .
Else
x=0: y=0: i=1
Do While Mid(xs, i, 1) <> "("
i=i+1
Loop
x=i-1
y=Len(xs)-i-1
fm =
fz= Val (Mid(xs, 1, x)) * power(y)+Val (Mid(xs, i+1, y))-Val (Mid(xs, 1, x))
fz=Val(zs)*fm+fz
End If
End If
Label2. Caption = Str(fz / gcd(fz, fm)) + "/"+ Str(fm / gcd(fz, fm))
End Sub
Function gcd (ByVal m As Long, ByVal n As Long) As Long
Dim r As Long
Do While m Mod n<>0
r= m Mod n
m=n
n=r
Loop
End Function
Function f(s As String) As Boolean '循环节判断
'函数返回True代表循环小数,False 不是循环小数,代码略
End Function
Function power(x As Integer) As Long '返回10的x次方
'代码略
End Function