【四技試題】
【C】01-1.以下是一個加上行號的Do迴圈指令Visual Basic程式片段,執行後Ans之值為何?
(A)9 (B)14 (C)40
(D)280。
1
Dim i, Ans As Integer
2 Ans = 1
3 i = 1
4 Do While i <= 10 |
T |
T |
T |
T |
F |
5 If i Mod 2 = 0 Then |
F |
T |
F |
T |
|
6 Ans = Ans * i |
|
1 * 4 = 4 |
|
4 * 10 = 40 |
|
7 End If |
|
|
|
|
|
8 i = i + 3 |
1 + 3 = 4 |
4 + 3 = 7 |
7 + 3 = 10 |
10 + 3 = 13 |
|
9 Loop
【B】01-2.續上題,要將上列程式改以For迴圈指令取代,下列程式第4行之中有X、Y和Z等三個變數,應該在行號3同一行後方撰寫哪一行指令指定其值,才能獲得相同的結果? (A)X = 1: Y = 3: Z = 10 (B)X = 1: Y = 10: Z = 3 (C)X = 3: Y = 10: Z =
1 (D)X = 10: Y = 1: Z = 3。[100商業]
1 Dim i, Ans, X, Y, Z As
Integer
2 Ans = 1
3 X = 1: Y = 10: Z = 3
4
For i = X To Y Step Z → X為初值,Y為終值,Z為變化值
5 If i Mod 2 = 0 Then
6 Ans
= Ans * i
7 End If
8 Next
【A】02.下列Visual Basic程式片段,若執行後power之值為8,則X之值應設為多少? (A)2 (B)4 (C)6 (D)8。[100管理]
Dim i, power, N, X As Integer
i = 1: power = 1: N = 3: X = ______
Do While i <= N
Power = power * X → 執行3次,power = X ^ 3 = 8,X = 2
i = i + 1
Loop
【C】03.下列Visual Basic的7行程式執行運算後,如果要得到下面所列的執行結果,請問程式第三行空白處應填入哪一個運算式? (A)i + 1 (B)Int(i) + 1 (C)Abs(i) + 1 (D)i。[101商業]
Dim i,
j As Integer For i =
-4 To 4 For j = 1 To _____ Print "*"; Next j Print Next i
Abs(i):取i的絕對值 |
[執行結果] ***** **** *** ** * ** *** **** ***** |
【A】04.下列哪一個Visual Basic程式語言敘述,會先判斷測試條件為真(True)時,才執行迴圈內的敘述? (A)Do While...Loop
(B)Do Until...Loop (C)Do...Loop While (D)Do...Loop Until。[101管理]
【B】05.執行完以下Visual Basic程式,總共會在螢幕顯示幾列結果? (A)5 (B)9 (C)45
(D)81。[101管理]
Private
Sub Form_Activate()
Dim i, j As Integer
For i = 1 To 9
For j = 1 To 9 Step 2
Print i; "x"; j;
"="; i * j; " ";
Next j
Print → 執行換列,共顯示9列
Next i
End Sub
【A】06.執行完下列Visual Basic程式片段後,會在螢幕顯示幾個星號? (A)5 (B)6 (C)9 (D)10。[101管理]
Dim A, B As Integer
B = 10
For A = 1
To B Step 1
If (A MOD 2 = 0) Then Print "*" → A=2, 4,
6, 8, 10時才顯示*,共5個*
Next A
【B】07.執行下列Visual Basic程式片段後,變數S的值為何? (A)-5 (B)-4 (C)8 (D)55。[102管理]
S = 1: R
= 1
For I = 1 To 10 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
S = S + I * R |
2 |
0 |
3 |
-1 |
4 |
-2 |
5 |
-3 |
6 |
-4 |
R = R * (-1) |
-1 |
1 |
-1 |
1 |
-1 |
1 |
-1 |
1 |
-1 |
1 |
Next I
【B】08.執行下列Visual Basic程式片段後,變數c的值為何? (A)0 (B)15 (C)30 (D)60。[102管理]
c = 0
For a =
1 To 30 Step 2 For b = 30 To 1 Step -1 If a = b Then c = c + 1 |
a = 1、3、5、7、9、11、13、15、17、19、21、23、25、27、29,執行15回 b = 30、29、28、…、遞減至1,執行30回 a = b及c + 1,共執行15次,c = 15 |
End If
Next b
Next a
【B】09.執行下列Visual Basic程式片段後,變數A的值為何? (A)-1 (B)0 (C)1 (D)2。[103商業]
A = 0
For I = 2
to -1 → 迴圈未設定增加值,預設值為+1。終值-1 <
初值2,不會執行迴圈
A = A + I → A仍為0
Next I
【D】10.請問執下列Visual Basic程式碼後,在「訊息視窗(MsgBox)」上的顯示數值為何? (A)1 (B)5 (C)20
(D)120。[103資電]
Sub
Main()
Dim I As Integer
Dim result As Integer
result = 1
For I = 1 To 5
result = result * I → 1 * 2 * 3 * 4 * 5 = 120
Next
If I > 5 Then → 6 > 5成立
MsgBox(result) → 顯示120
ElseIf I <= 5 Then
MsgBox(i)
Else
MsgBox(20)
End If
End Sub
【C】11.執行下列Visual Basic程式片段後,變數Sum的值為何? (A)1 (B)95 (C)165 (D)385。[104商業]
Dim X, Y,
Sum
Sum = 0
For X = 1
To 10 Step 2
For Y = X To 1 Step -1
Sum = Sum + X → 1 + 3 * 3 + 5 * 5 + 7 * 7 + 9 * 9
= 165
Next Y
Next X
【B】12.執行下列Visual Basic程式片段後,變數B的值為何? (A)20 (B)21 (C)23 (D)24。[104管理]
A = 1: B
= 1
Do
While B < 20 |
T |
T |
T |
T |
F |
B = B + 2 * A |
1 + 2 * 1 = 3 |
3 + 2 * 2 = 7 |
7 + 2 * 3 = 13 |
13 + 2 * 4 = 21 |
|
A = A + 1 |
1 + 1 = 2 |
2 + 1 = 3 |
3 + 1 = 4 |
4 + 1 = 5 |
|
Loop
【C】13.執行下列Visual Basic程式片段後,變數A的值為何? (A)-1 (B)-4 (C)4 (D)5。[104管理]
A = 1: B
= 1
For I =
5 To 1 Step -1 |
5 |
4 |
3 |
2 |
1 |
A = A + I * B |
1+5*1=6 |
6+4*(-1)=2 |
2+3*1=5 |
5+2*(-1)=3 |
3+1*1=4 |
B = B * (-1) |
1*(-1)=(-1) |
(-1)*(-1)=1 |
1*(-1)=(-1) |
(-1)*(-1)=1 |
1*(-1)=(-1) |
Next I
【D】14.執行下列Visual Basic程式片段後,變數S的值為何? (A)(((1, 0), 2), 3) (B)(1, (2, (3, 0))) (C)(((3, 0), 2), 1) (D)(3,
(2, (1, 0)))。[105商業]
Dim K As Integer
Dim S As
String
S =
"0"
For K =
1 To 3 |
1 |
2 |
3 |
S = "(" & K &
", " & S & ")" |
(1, 0) |
(2, (1, 0)) |
(3, (2, (1, 0))) |
Next K
【C】15.執行下列Visual Basic程式片段後,變數MyVal的值為何? (A)4 (B)8 (C)11 (D)12。[105商業]
Dim MyVal As Integer
MyVal = 0
Do
MyVal = MyVal + 2 |
0 + 2 = 2 |
|
|
5 + 2 = 7 |
8 + 2 = 10 |
Do |
|
|
|
|
|
MyVal = MyVal + 1 |
2 + 1 = 3 |
3 + 1 = 4 |
4 + 1 = 5 |
7 + 1 = 8 |
10 + 1 = 11 |
If MyVal > 4 Then Exit Do |
F |
F |
T |
T |
|
Loop |
|
|
|
|
|
If MyVal > 8 Then Exit Do |
|
|
F |
F |
T |
Loop
【A】16.執行下列Visual Basic程式片段後,變數Count的值為何? (A)63 (B)64 (C)73 (D)74。[105管理]
Dim Sum,
Count, X As Integer
Sum = 0: Count
= 0
Do
While Sum < 10 |
T |
|
|
|
T |
T |
F |
X = 0 |
0 |
|
|
|
0 |
0 |
|
Do |
|
|
|
|
|
|
|
X = X + Sum + 1 |
1 |
2 |
3 |
4 |
5 |
10 |
|
Count = Count + 10 |
10 |
20 |
30 |
40 |
51 |
62 |
|
Loop Until X > 3 |
F |
F |
F |
T |
T |
T |
|
Sum = Sum + X |
|
|
|
4 |
9 |
19 |
|
Count = Count + 1 |
|
|
|
41 |
52 |
63 |
|
Loop
【A】17.執行下列Visual Basic程式片段後,變數I的值為何? (A)505 (B)455 (C)555 (D)545。[105管理]
Dim I, J,
K As Integer
I = 1
For J =
1 To 2 |
1 |
2 |
K = 4 * I ^ 3 |
4 * 1 ^ 3 = 4 |
4 * 5 ^ 3 = 500 |
I = I + K |
1 + 4 = 5 |
5 + 500 = 505 |
Next J
【B】18.執行下列Visual Basic程式片段後,變數S的值為何? (A)44 (B)45 (C)46 (D)54。[105管理]
Dim I, K, S As Integer
S = 0
For I =
10 To 1 Step -1 For K = 2 To I S = S + 1 |
I = 10,K執行9次;I = 9,K執行8次;依序類推; I = 3,K執行2次;I = 2,K執行1次。 9 + 8
+ 7 + 6 + 5 + 4 + 3 + 2 + 1 = 45 |
Next K
Next I
【D】19.執行下列Visual Basic程式片段,變數Sum的值為何? (A)200 (B)1200 (C)1800 (D)4200。[106商業]
Dim I, S, Sum As Integer
Sum = 0: I = 0
Do
I = I + 10 |
0 + 10 = 10 |
10 + 10 = 20 |
20 + 10 = 30 |
S = I ^ 2 * 2 |
10 ^ 2 * 2 = 200 |
20 ^ 2 * 2 = 800 |
30 ^ 2 * 2 = 1800 |
Sum = 2 * Sum + S |
2 * 0 + 200 = 200 |
2 * 200 + 800 = 1200 |
2 * 1200 + 1800 = 4200 |
Loop
While I < 30 |
T |
T |
F |
【C】20.執行下列Visual Basic程式片段後,變數Count值為何? (A)14 (B)15 (C)16 (D)17。[106管理]
Dim Sum, Count, A As Integer
Sum = 1: Count = 0: A = 1
Do
Do
A = A + Sum |
2 |
3 |
4 |
5 |
6 |
7 |
9 |
Count = Count + 2 |
2 |
4 |
6 |
8 |
10 |
12 |
15 |
Loop While A <= 6 |
T |
T |
T |
T |
T |
F |
F |
Sum = Sum + A |
|
|
|
|
|
8 |
17 |
Count = Count + 1 |
|
|
|
|
|
13 |
16 |
A = 1 |
|
|
|
|
|
1 |
1 |
Loop
Until Sum >= 15 |
|
|
|
|
|
F |
T |
【C】21.執行下列Visual Basic程式片段後,變數Sum的值為何? (A)5 (B)25 (C)30 (D)36。[106管理]
Dim Sum As Integer = 0
Dim I As Integer=1
Dim J As Integer=1
For I = 0 To 5 → 從0 ~ 5執行6回
For J = 1 To 5 → 從1 ~ 5執行5回
Sum = Sum + 1 → 累加6 * 5 = 30
Next
Next
【C】22.執行下列Visual Basic程式片段後,變數Total的值為何? (A)8 (B)12 (C)13 (D)15。[107商業]
Dim n, Total As Integer
n = 16: Total = 0
Do While n > 1 |
16 > 1 = T |
8 > 1 = T |
4 > 1 = T |
2 > 1 = T |
1 > 1 = F |
n = n / 2 |
16 / 2 = 8 |
8 / 2 = 4 |
4 / 2 = 2 |
2 / 2 = 1 |
|
If n <> 2 Then |
8 <> 2 = T |
4 <> 2 = T |
2 <> 2 = F |
1 <> 2 = T |
|
Total = Total + n |
0 + 8 = 8 |
8 + 4 = 12 |
|
12 + 1 = 13 |
|
End If
Loop
【C】23.執行下列Visual Basic程式片段後,變數Sum的值為何?
(A)4 (B)6 (C)9 (D)12。[107商業]
Dim Sum, Maximum, i As Integer
Sum = 0:
Maximum = 5
Do While
Maximum > 0 |
T |
T |
T |
|
T |
|
T |
|
|
F |
For i = Maximum To 5 Step 2 |
5 |
4 |
3 |
5 |
2 |
4 |
1 |
3 |
5 |
|
Sum = Sum + 1 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
|
Next i |
|
|
|
|
|
|
|
|
|
|
Maximum = Maximum - 1 |
4 |
3 |
|
2 |
|
1 |
|
|
0 |
|
Loop
【C】24.執行下列Visual Basic程式片段後,變數S的值為何? (A)24 (B)25 (C)26 (D)27。[107管理]
Dim S, I, N As Integer
S = 1: N
= 2
For I = 1
To 10 Step N
S = S + I → 1 + 1 + 3 + 5 + 7 + 9 = 26
Next
【C】25.執行下列Visual Basic程式片段後,變數counter的值為何?
(A)4 (B)5 (C)6 (D)7。[107管理]
Dim a, b,
counter As Integer
counter =
0
For a = 1
To 5
For b = a To 1 Step - 1 If b Mod 2 = 0 Then counter = counter + 1 Next b |
(a,
b) → (2, 2),(3, 2),(4, 4),(4, 2),(5, 4),(5, 2)時,執行counter = counter + 1,計6次 |
Next a
【B】26.執行以下Visual Basic的程式片段後,S的結果為何? (A)5 (B)6 (C)7 (D)8。[108商業]
Dim data A(3) As Integer: dataA(0) = 3: dataA(1) = 4:
dataA(2) = 5
Dim S As Integer: S = 0
Dim idx As Integer
For idx = 10 To 12 |
10 |
11 |
12 |
S = S + idx
Mod dataA(idx - 10) |
0+10 Mod 3=1 |
1+11 Mod 4=4 |
4+12 Mod 5=6 |
Next idx
【D】27.下列Visual Basic程式片段執行後,S的值為何? (A)0
(B)6 (C)12 (D)15。[108商業]
Dim i, S, Maximum As Integer
S = 0:
Maximum = 5
Do
While Maximum > 0 |
T |
T |
T |
T |
T |
For i = 1 To Maximum |
1~5 |
1~4 |
1~3 |
1~2 |
1 |
S = S + 1 |
0+1*5=5 |
5+1*4=9 |
9+1*3=12 |
12+1*2=14 |
14+1=15 |
Next i |
|
|
|
|
|
Maximum = Maximum - 1 |
4 |
3 |
2 |
1 |
0 |
Loop
【C】28.下列Visual Basic程式片段執行後,S的值為何? (A)0 (B)24 (C)48 (D)96。[108商業]
Dim S As
Integer
S = 0
For k =
9 To 16 Step 2 |
9 |
11 |
13 |
15 |
S = S + k |
0 + 9 = 9 |
9 + 11 = 20 |
20 + 13 = 33 |
33 + 15 = 48 |
Next k
【D】29.請問下圖的Visual Basic程式碼執行完後,變數x的值為何? (A)1001 (B)55 (C)641 (D)89。[108資電]
Sub
Main()
Dim i, x, x1, x2 As Integer
x = 1000: x1 = 1: x2 = 0
For i = 1 To 10 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
x = x1 + x2 |
1 |
2 |
3 |
5 |
8 |
13 |
21 |
34 |
55 |
89 |
x2 = x1 |
1 |
1 |
2 |
3 |
5 |
8 |
13 |
21 |
34 |
55 |
x1 = x |
1 |
2 |
3 |
5 |
8 |
13 |
21 |
34 |
55 |
89 |
Next
Console.WriteLine(x) → 顯示89
End Sub
【B】30.下列Visual Basic程式執行後,變數S的值為何? (A)70 (B)71 (C)72 (D)73。[108管理]
Dim S, C, I As Integer
S = 5: C = 3
While C <= 8 → C = 3, 4, 5, 6, 7, 8,計33次
For I = 1 To C
S = S + 2 → S = 5 + 2 × 33 = 71
Next I
C = C + 1
End While
【D】31.執行下列Visual Basic程式片段後,變數S的值為何? (A)45 (B)46 (C)54 (D)55。[108管理]
Dim A, B, S As Integer
S = 0
For A = 1
To 10 → A = 1 ~ 10
For B = 11 - A To 1 Step -1 → B = 10 ~ 1
S = S + 1 → S連加55次
Next B
Next A
【B】32.執行下列Visual
Basic(VB)程式片段後,變數Z的值為何? (A)32 (B)50 (C)54 (D)62。[109商業]
Dim A, B, Z as
Integer
Z = 0
For A = 1 to 4 Step 3 |
1 |
|
|
|
4 |
|
|
For B = A to 8 Step 2 |
1 |
3 |
5 |
7 |
4 |
6 |
8 |
Z = Z + A + B |
2 |
6 |
12 |
20 |
28 |
38 |
50 |
Next B
Next A
【D】33.執行下列Visual
Basic(VB)程式片段後,變數Y的值為何? (A)01 (B)101 (C)01101
(D)10101101。[109商業]
Dim K as Integer
Dim X, Y as String
X = "0": Y =
"1"
For K = 1 to
2 |
1 |
2 |
X = X & Y |
"0" & "1" = "01" |
"01" & "101" = "01101" |
Y = Y & X |
"1" & "01" = "101" |
"101" & "01101" = "10101101" |
Next K
【C】34.執行下列Visual
Basic(VB)程式片段後,下列敘述何者正確? (A)K為1~99中2的倍數但不是5的倍數的數字之個數
(B)K為1~99中2的倍數或5的倍數的數字之個數
(C)K為1~99中2的倍數且是5的倍數的數字之個數
(D)K為1~99中5的倍數但不是2的倍數的數字之個數。[109商業]
Dim I, K as Integer
I = 1: K = 0
Do While(I < 100)
If(I Mod 2 = 0) And (I Mod 5 = 0) Then K = K + 1 |
從I = 1、Do
While(I < 100)、I = I + 1,可判定I介於1~99之間 從(I Mod 2 = 0) And (I Mod 5 = 0)、K = K + 1,可判定在求2的倍數且是5的倍數的數字之個數 |
I = I + 1
Loop
【B】35.執行下列Visual Basic程式片段後,變數Z的結果為何? (A)我愛愛我愛 (B)愛我愛愛我 (C)愛我愛我愛 (D)愛愛我愛我。[110商業]
Dim X, Y, Z As String
Dim K As Integer
Z = ""
X = "我"
Y = "愛"
For K = 1 To 3 |
1 |
2 |
3 |
Z = Y & X |
Z=愛我 |
Z=愛我愛 |
Z=愛我愛愛我 |
X = Y |
X=愛 |
X=愛我 |
X=愛我愛 |
Y= Z |
Y=愛我 |
Y=愛我愛 |
Y=愛我愛愛我 |
Next K
【C】36.執行下面Visual Basic程式片段後,sum的值為何? (A)2 (B)4 (C)6
(D)8。[110商業]
Dim i, j, k, sum As Integer
sum = 0
i = 0: j = 0: k = 0
For i = 1 To 2 |
1 |
|
|
2 |
|
|
For j = 1 To
2 |
1 |
2 |
|
1 |
2 |
|
For k = 1 To
j |
1 |
1 |
2 |
1 |
1 |
2 |
sum = sum
+ 1 |
0+1=1 |
1+1=2 |
2+1=3 |
3+1=4 |
4+1=5 |
5+1=6 |
Next k
Next j
Next i
【C】37.執行下列Visual Basic程式片段後,變數C的值為何? (A)5 (B)6 (C)7
(D)12。[110商業]
Dim A, B, C As Integer
C = 0
For A = 1 To 5 Step 2 |
1 |
|
|
|
3 |
|
5 |
For B = 1 To
4 Step A |
1 |
2 |
3 |
4 |
1 |
4 |
1 |
C = C + 1 |
0+1=1 |
1+1=2 |
2+1=3 |
3+1=4 |
4+1=5 |
5+1=6 |
6+1=7 |
Next B
Next A
【B】38.執行下列Visual Basic程式片段後,變數N的值為何? (A)3 (B)5 (C)27
(D)55。[110管理]
Dim A, N As Integer
A = 13: N = 3
While A < 50 |
13 < 50 |
27 < 50 |
55 < 50 |
A = A * 2 + 1 |
13 * 2 + 1 = 27 |
27 * 2 + 1 = 55 |
|
N = N + 1 |
3 + 1 = 4 |
4 + 1 = 5 |
|
End While
【二技試題】
【A】01.下列Visual
Basic程式片段執行後,結果為何?
(A)HappyBirthday (B)Happy (C)BirthdayHappy (D)Birthday。[96護理]
x = 10: y = 4
If x >= 10 And y < 6 Then → 10 >= 10 And 4
< 6成立
Print "Happy"; → 顯示"Happy"
End If
Print "Birthday" → 顯示"Birthday"
【D】02.下列Visual Basic語言片段程式執行後,下列哪一項是正確的? (A)a = 3 (B)b = 3 (C)a
= 5 (D)b = 5。[100管理]
Dim a, b As Integer
a = 1: b = 2
If (a > 1) Then → 1 > 1不成立
a = a + 1
Else
b = b + 2 → 2 + 2 = 4
End If
If (b > 2) Then → 4 > 2成立
b = b + 1 → 4 + 1 = 5
Else
a = a + 2
End If
【D】03.有一Visual Basic的迴圈程式片段「For I = 2 To 11 Step 3」。請問執行該程式片段後,並脫離迴圈時,I值等於多少? (A)11 (B)12 (C)13 (D)14。[91護理]
I = 2、5、8、11、14(超出終值)
【C】04-1.下列程式執行後,全部印出幾個*號? (A)4 (B)5 (C)6
(D)7。
I = 0: J = 10
Do
I = I + 2 |
0 + 2 = 2 |
2 + 2 = 4 |
4 + 2 = 6 |
6 + 2 = 8 |
8 + 2 = 10 |
J = J -
1 |
10 - 1 = 9 |
9 - 1 = 8 |
8 - 1 = 7 |
7 - 1 = 6 |
6 - 1 = 5 |
Print "*"; |
* |
* |
* |
* |
* |
Loop
While (I < 10) |
T |
T |
T |
T |
F |
Print
"*" → 印出6個*
Print J → 印岀5
【B】04-2.續上題程式,最後印出變數J的值為何? (A)4 (B)5 (C)6 (D)7。[92護理]
【A】05-1.下列虛擬碼執行後,何者正確? (A)a的值為7 (B)a的值為10 (C)b的值為20 (D)b的值為22。
a = 1: b = 2
do while (a < 10 and b < 20) |
T |
T |
T |
T |
T |
T |
F |
a = a + 1 |
2 |
3 |
4 |
5 |
6 |
7 |
|
if (a等於奇數) then |
F |
T |
F |
T |
F |
T |
|
b = b + 5 |
|
9 |
|
16 |
|
23 |
|
else |
|
|
|
|
|
|
|
b = b + 2 |
4 |
|
11 |
|
18 |
|
|
end if
end do
【D】05-2.承接上題,下列何者是上題虛擬碼的流程圖?。[93管理]
|
|
|
|
【B】06.考慮下列BASIC程式片段,則執行後,其顯示的結果為 (A)9 (B)22 (C)7 (D)120。[93管理]
Z = 0
FOR X = 1 TO 5 STEP 2 |
1 |
3 |
5 |
FOR
Y = 1 TO X |
1 |
1 ~ 3 |
1 ~ 5 |
Z = Z + Y |
0 + 1 = 1 |
1 + 1 + 2 + 3 = 7 |
7 + 1 + 2 + 3 + 4 + 5 = 22 |
NEXT
Y
NEXT X
PRINT Z → 顯示22
【D】07.若欲求1/2 + 3/4 + 7/6 + 13/8 + 21/10 +…+ N/100,則下列BASIC程式的第5行應為何,才能獲得正確結果? (A)J = I - 1
(B)J = 2 * I - 3 (C)J = I * I - 1 (D)J = J + I。[93管理]
第1行 S = 0
第2行 J = 1
第3行 FOR I = 2 TO 100 STEP 2
第4行 S = S + J / I
第5行 ________
第6行 NEXT I
第7行 PRINT S
第8行 END
【B】08-1.下面BASIC程式片段執行後,其最後顯示Z值的結果為何? (A)15 (B)18 (C)72 (D)120。
Z = 0
For X =
1 To 2 |
1 |
2 |
For Y = 1 To 3 |
1 ~ 3 |
1 ~ 3 |
Z = Z + X * Y |
0 + 1 * 1 + 1 * 2 +
1 * 3 = 6 |
6 + 2 * 1 + 2 * 2 +
2 * 3 = 18 |
Next Y
Next X
Print Z → 顯示18
【C】08-2.上題的程式中,第四行指令Z
= Z + X * Y總共執行了幾次? (A)2
(B)3 (C)6 (D)12。[94護理]
【B】09.下列BASIC程式片段,敘述行號30總共執行幾次? (A)4 (B)5 (C)6 (D)7。[95護理]
10 I = 22: Y = 6
20 While I <> Y |
T |
T |
T |
T |
T |
F |
30 If I >
Y Then |
T |
T |
T |
F |
T |
|
40 I = I - Y |
22 - 6 = 16 |
16 - 6 = 10 |
10 - 6 = 4 |
|
4 - 2 = 2 |
|
50 Else |
|
|
|
|
|
|
60 Y = Y - I |
|
|
|
6 - 4 = 2 |
|
|
70 End If |
行號30總共執行5次 |
80 Wend
90 End
【D】10.下列BASIC程式片段執行後,W的值為何? (A)11 (B)14 (C)18 (D)23。[95護理]
W = 1
For X = 1 To 5 Step 2 |
1 |
3 |
5 |
For Y = 1 To X |
1 |
1 ~ 3 |
1 ~ 5 |
W = W + Y |
1 + 1 = 2 |
2 + 1 + 2 + 3 = 8 |
8 + 1 + 2 + 3 + 4 +
5 = 23 |
Next Y
Next X
【C】11.下列Visual Basic程式片段執行後,Sum值為何? (A)100 (B)101 (C)5050
(D)5051。[96護理]
Sum = 0
For i = 1 To 100
Sum = Sum + i → 從1加到100的和 = (1 + 100) * 100 = 5050
Next i
Print Z
【A】12.執行下列BASIC程式片段後,會輸出何種結果? (A)24 (B)55
(C)19 (D)23。[97管理]
C = 0
For A = 2 To 6 Step 4 |
2 |
6 |
For B = 1 To A |
1 ~ 2 |
1 ~ 6 |
C = C + B |
0 + 1 + 2 = 3 |
3 + 1 + 2 + 3 + 4 +
5 + 6 = 24 |
Next B
Next A
Print C → 輸出24
【A】13.執行下列BASIC程式片段後,會輸出何種結果? (A)19 (B)17
(C)15 (D)18。[97管理]
A = 1
For B = 0 To 2 |
0 |
1 |
2 |
For C = 1 To 3 |
1~3 |
1~3 |
1~3 |
A = A + B * C |
1+0*1+0*2+0*3=1 |
1+1*1+1*2+1*3=7 |
7+2*1+2*2+2*3=19 |
Next C
Next B
Print A → 輸出19
【C】14.執行下列BASIC程式片段後,Total的值為何? (A)10 (B)20 (C)30 (D)40。[97護理]
Total = 0: n = 0
While n <= 10 |
T |
T |
T |
T |
T |
T |
Total = Total + n |
0+0=0 |
0+2=2 |
2+4=6 |
6+6=12 |
12+8=20 |
20+10=30 |
n =
n + 2 |
0+2=2 |
2+2=4 |
4+2=6 |
6+2=8 |
8+2=10 |
10+2=12 |
Wend
【C】15.執行下列BASIC程式片段後,列印結果總共有幾個星號(*)? (A)37 (B)40 (C)41 (D)44。[98管理]
Z = 0
For I = -5 To 5
For J = -5 To
5
If I = Z Or
J = Z Or I = J Or I = -J Then Print " * "; Else Print " ";
Next J
Print
Next I
I |
J |
Z |
|
I |
J |
Z |
|
總共列印41個* |
-5 |
-5 |
0 |
I = J |
1 |
-1 |
0 |
I = -J |
|
0 |
0 |
J = Z |
0 |
0 |
J = Z |
|||
5 |
0 |
I = -J |
1 |
0 |
I = J |
|||
-4 |
-4 |
0 |
I = J |
2 |
-2 |
0 |
I = -J |
|
0 |
0 |
J = Z |
0 |
0 |
J = Z |
|||
4 |
0 |
I = -J |
2 |
0 |
I = J |
|||
-3 |
-3 |
0 |
I = J |
3 |
-3 |
0 |
I = -J |
|
0 |
0 |
J = Z |
0 |
0 |
J = Z |
|||
3 |
0 |
I = -J |
3 |
0 |
I = J |
|||
-2 |
-2 |
0 |
I = J |
4 |
-4 |
0 |
I = -J |
|
0 |
0 |
J = Z |
0 |
0 |
J = Z |
|||
2 |
0 |
I = -J |
4 |
0 |
I = J |
|||
-1 |
-1 |
0 |
I = J |
5 |
-5 |
0 |
I = -J |
|
0 |
0 |
J = Z |
0 |
0 |
J = Z |
|||
1 |
0 |
I = -J |
5 |
0 |
I = J |
|||
0 |
-5, -4, -3, -2, -1 |
0 |
I = Z |
|
|
|
|
|
0 |
0 |
I = Z, J = Z, I = J |
|
|
|
|
||
1, 2, 3, 4, 5 |
0 |
I = Z |
|
|
|
|
【D】16.若要利用下列BASIC程式片段印出(1 * 1 + 1 * 2) + (2 * 1
+ 2 * 2 + 2 * 3) + (3 * 1 + 3 * 2 + 3 * 3 + 3 * 4)的總和,則下列空格(1)處應填入的內容為何? (A)4 (B)4 - I (C)I (D)I
+ 1。[98管理]
Total = 0
For I = 1 To 3
For J = 1 To
(1)
Total =
Total + I * J
Next J
Next I
Print Total
【B】17.有一Visual Basic程式用來計算2 + 4 + 6 +...+ 100,其程式片段如下:
result = 0
For i = 2 To 10 Step 2 → 終值為10
result =
result + i
Next I
有關此程式片段,下列敘述何者正確? (A)會發生語法錯誤 (B)無法計算出2 + 4 + 6 +...+ 100的結果 (C)此程式無法執行 (D)執行結果result為2550。[99管理]
【B】18.下列Visual Basic語言片段程式執行後,下列哪一項是正確的? (A)i = 9 (B)i
= 10 (C)sum = 99 (D)sum = 100。[100管理]
Dim i, sum As Integer
i = 1: sum = 0
While ((i < 10) And (sum < 100)) |
T |
T |
T |
T |
T |
T |
T |
T |
T |
F |
If (i Mod 2
= 0) Then |
F |
T |
F |
T |
F |
T |
F |
T |
F |
|
sum = sum
+ i * 2 |
|
5 |
|
16 |
|
33 |
|
56 |
|
|
Else |
|
|
|
|
|
|
|
|
|
|
sum = sum
+ i |
1 |
|
8 |
|
21 |
|
40 |
|
65 |
|
End If |
|
|
|
|
|
|
|
|
|
|
i = i + 1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
|
End While
【D】19.下列Visual Basic語言片段程式執行後,sum的值為多少? (A)24 (B)25 (C)44 (D)45。[100管理]
Dim k, sum, j As Integer
sum = 1
For k = 3 To 6 Step 2 |
3 |
5 |
sum = sum + k |
1 + 3 = 4 |
22 + 5 = 27 |
For j = 3 To 6 |
3 ~ 6 |
3 ~ 6 |
sum = sum + j |
4 + 3 + 4 + 5 + 6 =
22 |
27 + 3 + 4 + 5 + 6 = 45 |
Next
Next
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。