【技藝競賽試題】
【B】01.下列BASIC程式片段執行後,其顯示的結果為
(A)42 (B)23 (C)22 (D)32。[97技競]
W = 1
FOR X = 1 TO 5 STEP 2
FOR Y = 1 TO X
W = W + Y
NEXT Y
NEXT X
PRINT W
X |
Y |
W = W + Y |
X |
Y |
W = W + Y |
1 |
1 |
1 + 1 = 2 |
5 |
1~5 |
8 + 1 + 2 + 3 + 4 + 5 = 23 |
3 |
1~3 |
2 + 1 + 2 + 3 = 8 |
|
|
|
【D】02.依序執行下列敘述For
I = 1 To 3: For J = 1 To I: Print “*”: Next J: Next I,其結果將顯示幾個星號(*)? (A)3個 (B)4個 (C)5個 (D)6個。[97技競]
I |
J |
Print |
I |
J |
Print |
1 |
1 |
* |
3 |
1~3 |
*** |
2 |
1~2 |
** |
共顯示6個* |
【B】03.BASIC程式中,如用For…Next迴路計算1至100的偶數和,下列程式的空格內,應照順序填入那些數目,方可得到正確結果? (A)1,100,2 (B)2,100,2 (C)100,1,1 (D)100,2,2。[97技競]
For I = ___ To ___
Step ___
SUM = SUM + I
Next I
Print SUM
(A)1, 100,
2為計算1至100的奇數和。
【D】04.執行下列Visual
Basic程式片段後,何者的敘述錯誤? (A)a = 13 (B)b = 10 (C)x = 18 (D)y = 145。[98技競]
For a = 1 To 10 Step 3
For b = 1 To a - 1
x = x + 1: y = y + a
Next b
Next a
a |
b |
x = x + 1 |
y = y + a |
a |
b |
x = x + 1 |
y = y + a |
1 |
1 |
0 + 1 = 1 |
0 + 1 = 1 |
7 |
1~6 |
4 + 1 * 6 = 10 |
13 + 7 * 6 = 55 |
4 |
1~3 |
1 + 1 * 3 = 4 |
1 + 4 * 3 = 13 |
10 |
1~9 |
10 + 1 * 9 = 19 |
55 + 10 * 9 = 145 |
【A】05.以Visual Basic程式執行的結果,會是下列哪一項?
(A)90 (B)45 (C)30 (D)15。[99技競]
X = 0
For K = 1 To 5
For J = 1 To 3
X = X + K * J
Next J
Next K
Print X
K |
J |
X = X + K * J |
K |
J |
X = X + K * J |
1 |
1~3 |
0 + 1 * 1 + 1 * 2 + 1 * 3
= 6 |
4 |
1~3 |
36 + 4 * 1 + 4 * 2 + 4 *
3 = 60 |
2 |
1~3 |
6 + 2 * 1 + 2 * 2 + 2 * 3
= 18 |
5 |
1~3 |
60 + 5 * 1 + 5 * 2 + 5 *
3 = 90 |
3 |
1~3 |
18 + 3 * 1 + 3 * 2 + 3 *
3 = 36 |
|
|
|
【B】06.執行以下Visual
Basic程式片段後,請問c值為何?
(A)18 (B)19 (C)20 (D)21。[99技競]
Dim
c A Integer
c =
0
For
i = 0 To 5
j = 5 - i
Do
j = j - 1: c = c + j
Loop Until j <= 0
Print c
Next i
i |
j = 5 - i |
j = j - 1 |
c = c + j |
j <= 0 |
Print c |
0 |
5 - 0 = 5 |
5 - 1 = 4 |
0 + 4 = 4 |
F |
|
|
|
4 - 1 = 3 |
4 + 3 = 7 |
F |
|
|
|
3 - 1 = 2 |
7 + 2 = 9 |
F |
|
|
|
2 - 1 = 1 |
9 + 1 = 10 |
F |
|
|
|
1 - 1 = 0 |
10 + 0 = 10 |
T |
10 |
1 |
5 - 1 = 4 |
4 - 1 = 3 |
10 + 3 = 13 |
F |
|
|
|
3 - 1 = 2 |
13 + 2 = 15 |
F |
|
|
|
2 - 1 = 1 |
15 + 1 = 16 |
F |
|
|
|
1 - 1 = 0 |
16 + 0 = 16 |
T |
16 |
2 |
5 - 2 = 3 |
3 - 1 = 2 |
16 + 2 = 18 |
F |
|
|
|
2 - 1 = 1 |
18 + 1 = 19 |
F |
|
|
|
1 - 1 = 0 |
19 + 0 = 19 |
T |
19 |
3 |
5 - 3 = 2 |
2 - 1 = 1 |
19 + 1 = 20 |
F |
|
|
|
1 - 1 = 0 |
20 + 0 = 20 |
T |
20 |
4 |
5 - 4 = 1 |
1 - 1 = 0 |
20 + 0 = 20 |
T |
20 |
5 |
5 - 5 = 0 |
0 - 1 = -1 |
20 + (-1) = 19 |
T |
19 |
【C】07.執行下列Visual
Basic程式片段後,請問s值為何?
(A)20 (B)171 (C)190 (D)380。[99技競]
Dim
c As Integer
Dim
s As Double
c = 3: s = 1
While c <= 20
s = s * c / (c - 2): c = c + 1
Wend
Print s
c |
c <= 20 |
s = s * c / (c - 2) |
c = c + 1 |
3 |
T |
1 * 3 / (3 - 2) = 3 |
3 + 1 = 4 |
4 |
T |
3 * 4 / (4 - 2) = 6 |
4 + 1 = 5 |
5 |
T |
6 * 5 / (5 - 2) = 10 |
5 + 1 = 6 |
6 |
T |
10 * 6 / (6 - 2) = 15 |
6 + 1 = 7 |
7 |
T |
15 * 7 / (7 - 2) = 21 |
7 + 1 = 8 |
8 |
T |
21 * 8 / (8 - 2) = 28 |
8 + 1 = 9 |
9 |
T |
28 * 9 / (9 - 2) = 36 |
9 + 1 = 10 |
10 |
T |
36 * 10 / (10 - 2) = 45 |
10 + 1 = 11 |
11 |
T |
45 * 11 / (11 - 2) = 55 |
11 + 1 = 12 |
12 |
T |
55 * 12 / (12 - 2) = 66 |
12 + 1 = 13 |
13 |
T |
66 * 13 / (13 - 2) = 78 |
13 + 1 = 14 |
14 |
T |
78 * 14 / (14 - 2) = 91 |
14 + 1 = 15 |
15 |
T |
91 * 15 / (15 - 2) = 105 |
15 + 1 = 16 |
16 |
T |
105 * 16 / (16 - 2) =
120 |
16 + 1 = 17 |
17 |
T |
120 * 17 / (17 - 2) =
136 |
17 + 1 = 18 |
18 |
T |
136 * 18 / (18 - 2) =
153 |
18 + 1 = 19 |
19 |
T |
153 * 19 / (19 - 2) =
171 |
19 + 1 = 20 |
20 |
T |
171 * 20 / (20 - 2) = 190 |
20 + 1 = 21(跳出迴圈) |
【D】08.執行以下Visual
Basic程式片段,其執行結果為何?
(A)10 (B)11 (C)12 (D)編譯錯誤。[99技競]
Const a = 10
For i = 1 To 10
If I Mod 3 = 0 And i Mod 5 = 0 Then
a = a + 1
End If
Next i
Print a
Const a = 10,a為常數,不可指定值至常數,a
= a + 1會發生編譯錯誤。
【A】09.假設判斷閏年的方法為:若該年可以被400整除即為閏年,另若能被4整除且不可被100整除亦為閏年,其餘為平年。請問要判斷以下程式中的y值是否為閏年,空白處應分別填入何值? (A)Or, And Not (B)Or, And (C)And, Or Not (D)And, Or。[99技競]
Dim
y As Integer
y =
2000
If y
Mod 400 = 0 ___ y Mod 4 = 0 ___ y Mod 100 = 0 Then
Print y & “年是閏年”
Else
Print y & “年是平年”
End If
【A】10.下列程式執行後,L的值為多少?
(A)40 (B)39 (C)90 (D)91。[100技競]
Dim L = 35
Do Until Not (L < 40
Or L >= 90)
If L < 40 Then
L = L + 100
ElseIf L >= 90 Then
L = L - 99
End If
Loop
Do Until Not (L < 40 Or
L >= 90) = Do Until (L >= 40 And L < 90)
【D】11.下列Visual
Basic程式中,若想使程式執行完成後,i值為5,應在空白處填入何值?
(A)Exit For i = 5 (B)Exit If i = 5 (C)If i = 5 Then Exit (D)If i = 5 Then Exit
For。[100技競]
Dim i
For i = 1 To 10
____________
Next
【D】12.執行以下BASIC程式,其結果為何?
(A)0 (B)64 (C)256 (D)512。[100技競]
Dim
i, j As Double
Dim
n As Integer
n =
9: j = 1
For
i = 1 To n
j = j * ((i * 2) / (n - i + 1))
Next i
Print j
j = (2/9) * (4/8) * (6/7)
* (8/6) * (10/5) * (12/4) * (14/3) * (16/2) * (18/1) = 512
【B】13.對於重複結構,以下何者敘述正確?
(A)For…Next, While…Wend, Do…Loop, If…End If均屬於重複結構 (B)While…Wend與Do While… Loop執行過程是相同的
(C)Do While…Loop與Do
Until…Loop執行過程是相同的 (D)Do Until…Loop與Do…Loop Until執行過程是相同的。[100技競]
【C】14.執行以下BASIC程式,其結果為何?
(A)15 (B)17 (C)22 (D)27。[100技競]
Dim
S As Integer, I As Integer, J As Integer
S = 0: I = 1
While I <= 5
For J = 1 To I
S = S + J
Next J
I = I +
2
End While
Print S
I |
I <= 5 |
J |
S = S + J |
I = I + 2 |
1 |
T |
1 |
0 + 1 = 1 |
1 + 2 = 3 |
3 |
T |
1~3 |
1 + 1 + 2 + 3 = 7 |
3 + 2 = 5 |
5 |
T |
1~5 |
7 + 1 + 2 + 3 + 4 + 5 = 22 |
5 + 2 = 7(跳出迴圈) |
【D】15.下面所列的BASIC程式是在計算
(A)12 + 22 + 32 + 42 + 52
(B)12 + 32 + 52 + 72 + 92
(C)12 + 22 + 42 + 82 + 162
(D)12 + 22 + 42 + 72 + 112。[100技競]
Dim ST As Integer, Sum As
Integer, K As Integer
ST = 1: Sum = 0
For K = 1 To 5
Sum = Sum + ST * ST: ST = ST + K
Next K
Print(Sum)
【A】16.執行下列BASIC程式,其S結果為何? (A)20 (B)23 (C)28 (D)16。[101技競]
Dim S As Integer, K As Integer
K = 1: S
= 0
While K
< 8
If K >= 4 Then
K = K + 2: S = S
+ K
Else
S = S + K: K = K
+ 1
End IF
End While
K |
S |
K < 8 |
K >= 4 |
K = K + 2 |
S = S + K |
K = K + 1 |
1 |
0 |
T |
F |
|
0 + 1 = 1 |
1 + 1 = 2 |
2 |
1 |
T |
F |
|
1 + 2 = 3 |
2 + 1 = 3 |
3 |
3 |
T |
F |
|
3 + 3 = 6 |
3 + 1 = 4 |
4 |
6 |
T |
T |
4 + 2 = 6 |
6 + 6 = 12 |
|
6 |
12 |
T |
T |
6 + 2 = 8 |
12 + 8 = 20 |
|
8 |
20 |
F |
|
|
|
|
【A】17.執行下列BASIC程式,其I結果為何? (A)5 (B)10 (C)15 (D)6。[101技競]
Dim I, SUM As Integer
I = 0: SUM = 0
While I
< 5
SUM = SUM + I: I = I + 1
End While
I |
I < 5 |
SUM = SUM + I |
I = I + 1 |
0~4 |
T |
0 + 0 + 1 + 2 + 3 + 4 = 10 |
0 + 1 + 1 + 1 + 1 + 1 = 5 |
5 |
F |
|
|
【A】18.Y分別以1011和2202帶入下列程式執行,X的結果分別為何?
(A)1101, 2022 (B)1101, 2202 (C)1011, 2022 (D)1011, 2202。[101技競]
Dim Y, X As Integer
Y =
Do While Y > 0
X = X & (Y
Mod 10): Y = (Y - (Y Mod 10)) / 10
Loop
Console.WriteLine(X)
Y |
Y > 0 |
X = X & (Y Mod 10) |
Y = (Y - (Y Mod 10)) / 10 |
1011 |
T |
0 & (1011 Mod
10) = 01 |
(1011 - 1011
Mod 10) / 10 = 101 |
101 |
T |
01 & (101 Mod
10) = 011 |
(101 - 101 Mod
10) / 10 = 10 |
10 |
T |
011 & (10 Mod
10) = 0110 |
(10 - 10 Mod
10) / 10 = 1 |
1 |
T |
0110 & (1 Mod
10) = 01101 |
(1 - 1 Mod 10)
/ 10 = 0 |
2202 |
T |
0 & (2202 Mod
10) = 02 |
(2202 - 2202
Mod 10) / 10 = 220 |
220 |
T |
02 & (220 Mod
10) = 020 |
(220 - 220 Mod
10) / 10 = 22 |
22 |
T |
020 & (22 Mod
10) = 0202 |
(22 - 22 Mod
10) / 10 = 2 |
2 |
T |
0202 & (2 Mod
10) = 02022 |
(2 - 2 Mod 10)
/ 10 = 0 |
【C】19.執行下列BASIC程式,其S結果為何? (A)0 (B)15 (C)21 (D)56。[101技競]
Dim S As Integer, I As Integer, J As Integer
S = 0: I
= 6
While I
>= 6
For J = 1 To I
S = S + J
Next J
I = I - 1
End While
S = 0 + 1
+ 2 + 3 + 4 + 5 + 6 = 21
【B】20.執行下列程式,SUM之結果為何?
(A)14 (B)15 (C)26 (D)27。[101技競]
Dim I, J, K, SUM As Integer
I = 1: J
= 1: K = 1
While I
< 5
While J < 5
K = K + 1: J = J + 1
End While
I = I + 1
End While
SUM = I +
J + K
I |
J |
K |
I < 5 |
J < 5 |
K = K + 1 |
J = J + 1 |
I = I + 1 |
1 |
1~4 |
1~4 |
T |
T |
1 + 1 + 1 + 1 + 1 = 5 |
1 + 1 + 1 + 1 + 1 = 5 |
|
5 |
5 |
T |
F |
|
|
1 + 1 = 2 |
|
2 |
5 |
5 |
T |
F |
|
|
2 + 1 = 3 |
3 |
5 |
5 |
T |
F |
|
|
3 + 1 = 4 |
4 |
5 |
5 |
T |
F |
|
|
4 + 1 = 5 |
5 |
5 |
5 |
F |
|
|
|
|
【其他試題】
【3】01.配合While敘述,要使用哪一個當作迴圈的結尾敘述? (1)Exit (2)End (3)Wend
(4)Loop。
【4】02.配合Do敘述,要使用哪一個當作迴圈的結尾敘述? (1)Exit (2)End (3)Wend
(4)Loop。
【3】03.要跳出Do-Loop迴圈,可使用哪一個敘述? (1)Exit (2)Exit For
(3)Exit Do (4)以上皆非。
【3】04.在For敘述中,放在Step之後的是 (1)起始值 (2)界限值 (3)變更值 (4)控制變數。
【2】05.在For敘述中,放在To與Step之間的是 (1)起始值 (2)界限值 (3)變更值 (4)控制變數。
【1】06.For k = 3 To 18 Step 5的迴圈,[界限值]是 (1)18 (2)3 (3)5 (4)23。
【2】07.要跳出For-Next迴圈,可使用哪一個敘述? (1)Exit (2)Exit For
(3)Exit Do (4)以上皆非。
【3】08.For k = 1 To 13 Step 2的迴圈,執行完成離開迴圈時,k值等於 (1)13 (2)14 (3)15 (4)16。
【2】09.下列程式片段執行結果為何? (1)96
(2)110 (3)55 (4)45。
Sum = 0
For I = 1 To 10
Sum = Sum + I + I → 0 + (1
+ 1) + (2 + 2) +…+ (10 +
10) = 110
Next I
Print Sum → 顯示 110
【2】10.下列程式片段執行結果為何? (1)55 (2)25 (3)110 (4)30。
For I = 1 To 10 Step
2 → I = 1, 3,
5, 7, 9執行5次
S = S + I → S = 0 + 1
+ 3 + 5 + 7 + 9 = 25
Next
Print S → 顯示 25
【C】11.如下列之BASIC程式語言,其執行結果為何? (A)10 (B)20
(C)26 (D)41。
Dim i, j, s As Integer
s = 2
For i = 1 To 2
For j = 5 To 3 Step -2
s = s + i * j
Next j
Next i
Print s
i |
j |
s = s + i * j |
i |
j |
s = s + i * j |
1 |
5 |
2 + 1 * 5 = 7 |
2 |
5 |
10 + 2 * 5 = 20 |
3 |
7 + 1 * 3 = 10 |
3 |
20 + 2 * 3 = 26 |
【B】12.以下敘述何者有誤?
(A)For迴圈內的敘述可能不會被執行 (B)For迴圈的終值必須大於初值
(C)當迴圈內的敘述執行次數無法預估時使用Do迴圈 (D)For迴圈的Step增值變數不可以使用小數。
(A)For y = 1 To 5 Step -1,迴圈內的敘述不會被執行
(B)For y = 5 To 1 Step -1,初值5>終值1
(C)當迴圈內的敘述執行次數無法預估時使用Do迴圈;可預估執行次數時使用For迴圈
(D)For迴圈的Step增值變數是可以使用小數
【A】13.請問下列程式結果,k值為何? (A)17 (B)18 (C)19 (D)20。
Dim i, j, k As
Integer
k = 0
For i = 0 To 2
For j = 0 To 3
If (i <> 1 Or i <> 2 And j <> 1) Then
k = k + j
End If
Next j
Next i
Print k
i |
j |
i<>1 |
i<>2 |
j<>1 |
i<>2 And j<>1 |
i<>1 Or i<>2 And j<>1 |
K + j |
0 |
0 |
T |
T |
T |
T And
T = T |
T Or
T = T |
0 + 0
= 0 |
1 |
T |
T |
F |
T And
F = F |
T Or
F = T |
0 + 1
= 1 |
|
2 |
T |
T |
T |
T And
T = T |
T Or
T = T |
1 + 2
= 3 |
|
3 |
T |
T |
T |
T And
T = T |
T Or
T = T |
3 + 3
= 6 |
|
1 |
0 |
F |
T |
T |
T And
T = T |
F Or
T = T |
6 + 0
= 6 |
1 |
F |
T |
F |
T And
F = F |
F Or
F = F |
|
|
2 |
F |
T |
T |
T And
T = T |
F Or
T = T |
6 + 2
= 8 |
|
3 |
F |
T |
T |
T And
T = T |
F Or
T = T |
8 + 3
= 11 |
|
2 |
0 |
T |
F |
T |
F And
T = F |
T Or
F = T |
11 +
0 = 11 |
1 |
T |
F |
F |
F And
F = F |
T Or
F = T |
11 +
1 = 12 |
|
2 |
T |
F |
T |
F And T = F |
T Or F = T |
12 + 2 = 14 |
|
3 |
T |
F |
T |
F And T = F |
T Or F = T |
14 + 3 = 17 |
【B】14.下列Basic程式之目的是為將整數1~10中的奇數資料輸出,請問程式第二行之空格內須填入下列何者? (A)A / 2 = A \ 2 (B)A MOD 2 = 1 (C)A MOD 2 = 0 (D)A / 2 =
INT(A/2)。[87商業北夜]
FOR A = 1
TO 10
IF ______ THEN PRINT A
NEXT A
【D】15.下列Basic程式是在計算 (A)1 ^ 2 + 2 ^ 2 + 3 ^ 2 +...+ 7 ^ 2 (B)1 ^ 2 + 3 ^ 2 + 5 ^ 2 +...+
13 ^ 2 (C)1 ^ 2 + 2 ^ 2 + 4 ^ 2 +...+ 64 ^ 2 (D)1 ^ 2 + 2 ^ 2 + 4 ^ 2 + 7 ^ 2
+...+ 22 ^ 2。[87商業北夜]
ST = 1:
SUM = 0
FOR K = 1
TO 7
SUM = SUM + ST * ST
ST = ST + K
NEXT K
PRINT SUM
【B】16.下述程式中的空格填入什麼內容可以使顯示的執行結果為100? (A)K <= 10 (B)K <
10 (C)K > 10 (D)K <= 100。[87管理]
K = 1
WHILE
______
K = K + 1
WEND
PRINT K ^
2
【A】17.下列Basic程式執行完畢,B的值為何? (A)2 (B)4 (C)1 (D)22。[88資管保甄]
A = 100: B = 22: C = A MOD B
WHILE C
<> 0
A = B: B = C: C = A MOD B
WEND
A |
B |
C
= A Mod B |
C
<> 0 |
A
= B |
B
= C |
100 |
22 |
100 Mod
22 = 12 |
T |
22 |
12 |
22 |
12 |
22 Mod
12 = 10 |
T |
12 |
10 |
12 |
10 |
12 Mod
10 = 2 |
T |
10 |
2 |
10 |
2 |
10 Mod
2 = 0 |
F(跳出迴圈) |
|
|
【D】18.螢幕需列印以下結果0001 0010 0100 1000,則程式內之空格應填入那個運算式? (A)I = J (B)I <>
J (C)I = 4 - J (D)I = 5 - J。[88管理]
FOR
I = 1 TO 4
FOR J = 1 TO 4
IF ____ THEN PRINT "1";
ELSE PRINT "0";
NEXT J
PRINT
NEXT I
【C】19.執行以下之程式碼,在出現錯誤訊息前螢幕列印資料為 (A)1 2 3 (B)1 1
2 2 3 (C)1
1 2 1 3 (D)1 1
2 1 3 3。[88管理]
FOR I = 1
TO 10
PRINT I; PRINT (I / (I MOD 3));
NEXT I
I |
I
/ (I Mod 3) |
I |
I
/ (I Mod 3) |
1 |
1 / (1
Mod 3) = 1 |
3 |
3 / (3
Mod 3) = 3(出現錯誤訊息) |
2 |
2 / (2
Mod 3) = 1 |
|
|
【A】20.下列程式執行後輸出為何? (A)81 (B)99 (C)90 (D)225。[89工設]
For I = 1
To 9
For J = 1 To 9
While J <= 9
S = I * J:
J = J + 2
Wend
Next J
Next I
Print S
S = I * J
= 9 * 9 = 81
【綜合題】
【題目1】
S = 0: X = 1
While X <= 5
X = X + 1: S = S + X
Wend
Print S
X <= 5 |
X = X + 1 |
S = S + X |
X <= 5 |
X = X + 1 |
S = S + X |
1 <= 5 |
1 + 1 = 2 |
0 + 2 = 2 |
4 <= 5 |
4 + 1 = 5 |
9 + 5 = 14 |
2 <= 5 |
2 + 1 = 3 |
2 + 3 = 5 |
5 <= 5 |
5 + 1 = 6 |
14 + 6 = 20 |
3 <= 5 |
3 + 1 = 4 |
5 + 4 = 9 |
|
|
|
【題目2】
X = "ababaabbabaabab": Y
= "aba"
S = 1: C = 0
L = Len(Y) → L = 3
P = InStr(S, X, Y) → P = 1
While P > 0
S = P + L: C = C + 1
P = InStr(S, X, Y)
Wend
Print C
P > 0 |
S = P + L |
C = C + 1 |
P = InStr(S, X, Y) |
1 > 0 |
1 + 3 = 4 |
0 + 1 = 1 |
9 |
9 > 0 |
9 + 3 = 12 |
1 + 1 = 2 |
12 |
12 > 0 |
12 + 3 = 15 |
2 + 1 = 3 |
0 |
【題目3】
A = 1: S = 0
While A < 10
If A Mod 3 <> 0
Then S = S - 1 Else S = S - 3
A = A + 1
Wend
Print S
A |
S |
A < 10 |
A Mod 3 <> 0 |
S = S - 1 |
S = S - 3 |
A = A + 1 |
1 |
0 |
T |
T |
0 - 1 = -1 |
|
1 + 1 = 2 |
2 |
-1 |
T |
T |
(-1) - 1 = -2 |
|
2 + 1 = 3 |
3 |
-2 |
T |
F |
|
(-2) - 3 = -5 |
3
+ 1 = 4 |
4 |
-5 |
T |
T |
(-5) - 1 = -6 |
|
4
+ 1 = 5 |
5 |
-6 |
T |
T |
(-6) - 1 = -7 |
|
5
+ 1 = 6 |
6 |
-7 |
T |
F |
|
(-7) - 3 = -10 |
6
+ 1 = 7 |
7 |
-10 |
T |
T |
(-10) - 1 = -11 |
|
7
+ 1 = 8 |
8 |
-11 |
T |
T |
(-11) - 1 = -12 |
|
8
+ 1 = 9 |
9 |
-12 |
T |
F |
|
(-12) - 3 = -15 |
9
+ 1 = 10 |
10 |
-15 |
F |
|
|
|
|
【題目4】
N = 0: I = 0
While I < 50
If I Mod 13 = 1 Then N =
N + I: Print I
I = I + 3
Wend
Print N
I = 0, 3, 6, 9, 12, 15, 18, 21, 24,
27, 30, 33, 36, 39, 42, 45, 48
只有27 Mod 13 = 1符合,N = 0 + 27 = 27 → 答案
【題目5】
X = 186: Y = 24
While X <> Y
If X > Y Then X = X -
Y Else Y = Y - X
Wend
Print Y
X |
Y |
X <> Y |
X > Y |
X = X - Y |
Y = Y - X |
186 |
24 |
T |
T |
186 - 24 = 162 |
|
162 |
24 |
T |
T |
162 - 24 = 138 |
|
138 |
24 |
T |
T |
138 - 24 = 114 |
|
114 |
24 |
T |
T |
114 - 24 = 90 |
|
90 |
24 |
T |
T |
90 - 24 = 66 |
|
66 |
24 |
T |
T |
66 - 24 = 42 |
|
42 |
24 |
T |
T |
42 - 24 = 18 |
|
18 |
24 |
T |
F |
|
24 - 18 = 6 |
18 |
6 |
T |
T |
18 - 6 = 12 |
|
12 |
6 |
T |
T |
12 - 6 = 6 |
|
6 |
F |
F |
|
|
【題目6】求K值
Do While I > 0
For
J = 1 To I
K =
K + J Mod 5
Next
J
I =
I - 3
Print K
I |
J |
K = K + J Mod 5 |
I |
J |
K = K + J Mod 5 |
16 |
1 |
0 + 1 Mod 5 = 1 |
7 |
1 |
77 + 1 Mod 5 = 78 |
2 |
1 + 2 Mod 5 = 3 |
2 |
78 + 2 Mod 5 = 80 |
||
| |
|
| |
|
||
16 |
30 + 16 Mod 5 = 31 |
7 |
88 + 7 Mod 5 = 90 |
||
13 |
1 |
31 + 1 Mod 5 = 32 |
4 |
1 |
90 + 1 Mod 5 = 91 |
2 |
32 + 2 Mod 5 = 34 |
2 |
91 + 2 Mod 5 = 93 |
||
| |
|
| |
|
||
13 |
54 + 13 Mod 5 = 57 |
4 |
96 + 4 Mod 5 = 100 |
||
10 |
1 |
57 + 1 Mod 5 = 58 |
1 |
1 |
100 + 1 Mod 5 = 101 |
2 |
58 + 2 Mod 5 = 60 |
|
|
|
|
| |
|
|
|
|
|
10 |
77 + 10 Mod 5 = 77 |
|
|
|
【題目7】執行下列Visual Basic程式片段,其輸出結果為?
s = 1: t = 15
Do While t > 0
For k = 1 To t Step 2
s = s + t Mod 3
Next k
t = t - 5
Loop
Print s
k |
s = s + t Mod 3 |
t = t - 5 |
k |
s = s + t Mod 3 |
t = t - 5 |
1, 3, 5, 7, 9, 11, 13, 15 |
1 + 0 = 1 |
|
9 |
5 + 1 = 6 |
|
17 |
|
15 - 5 = 10 |
11 |
|
10 - 5 = 5 |
1 |
1 + 1 = 2 |
|
1 |
6 + 2 = 8 |
|
3 |
2 + 1 = 3 |
|
3 |
8 + 2 = 10 |
|
5 |
3 + 1 = 4 |
|
5 |
10 + 2 = 12 |
|
7 |
4 + 1 = 5 |
|
7 |
|
|
【題目8】
S = 0
FOR K = 1
TO 4 → 空轉4圈
NEXT K
Print S → 顯示
0
求結果?
【題目9】變數的K值是多少?
(1) For
K = 1 To 10 K = K + 2 Next K Print K |
(2) For K = 1 To 10 K = K + 2 Print K Next K |
|
K |
K + 2 |
|
1 |
1 + 2 = 3 |
|
4 |
4 + 2 = 6 (∵Step 1省略 ∴4 = 3 + 1) |
|
7 |
7 + 2 = 9 (∵Step 1省略 ∴7 = 6 + 1) |
|
10 |
10 + 2 = 12 (∵Step 1省略 ∴10 = 9 + 1) |
|
13 |
K值執行到12,還要回到For再加1,所以最後K是13 |
|
【題目10】下列程式執行結果為何?
A = 1: B = 2
For I = A - B To A +
B Step A / B → For I = -1 To 3 Step 0.5
Print I → 顯示-1,
-0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3
Next I
【題目11】利用VB撰寫用來計算1~100之間的奇數和之程式,則在下列空格內需填哪些數字?
Sum = 0
For I = 1 To 100 Step 1 →
I值1, 3, 5, …
Sum = Sum + I → I值1, 3, 5, …
I = I + 1
→ I值2,
4, 6, …
Next I
Print Sum
【題目12】執行程式後,a值為何?
Dim a As Integer, b As Integer
b = 1
For a = 1
To 100
If b >= 10 Then Exit For
If b Mod 5 = 1 Then
b = b + 5
End If
Next a
a |
b |
b
>= 10 |
b
Mod 5 = 1 |
b
= b + 5 |
1 |
1 |
F |
T |
1 + 5 =
6 |
2 |
6 |
F |
T |
6 + 5 =
11 |
3 |
11 |
T (跳出迴圈) |
|
|
【題目13】下列程式執行結果為何?
C = 0: S = 0
For X = 1 To 8 Step 2
For
Y = 1 To X - 2 Step 3
C = C + 2: S = S + Y
Next
Y
X
= X + 1
Next X
Print C - S
X |
Y |
C = C + 2 |
S = S + Y |
X = X + 1 |
1 |
1~-1 (不執行) |
|
|
1 + 1 = 2 |
4 (Step 2) |
1 |
0 +
2 = 2 |
0 +
1 = 1 |
4 + 1 = 5 |
7 (Step 2) |
1 |
2 +
2 = 4 |
1 +
1 = 2 |
|
7 |
4 (Step 3) |
4 +
2 = 6 |
2 +
4 = 6 |
7 + 1 = 8 |
Print C - S = 6 - 6 = 0
【題目14】下列程式執行後,c的值為何?
Dim c, i, j As Integer
c = 0
For i = 0 To 8
For
j = 0 To 8
If (i \ 3 + j \ 3) Mod 2 = 1 Then
c = c + 1
End If
Next
j
Next i
Print c
\是整數除法。符合(i \ 3 + j \ 3) Mod 2 = 1條件時,c要加1。
i |
j |
左列為符合條件,有36個組合: 3 * 3 + 3 * 6 + 3 * 3 = 36 |
0, 1, 2 |
3, 4, 5 |
|
3, 4, 5 |
0, 1, 2, 6, 7, 8 |
|
6, 7, 8 |
3, 4, 5 |
【題目15】
For I = 1 To 10 Step 3
Sum = Sum + I: I = I + 1
Next I
? Sum
I |
Sum
= Sum + I |
I
= I + 1 |
1 |
0 + 1 = 1 |
1 + 1 = 2 |
5 (Step 3) |
1 + 5 = 6 |
5 + 1 = 6 |
9 (Step 3) |
6 + 9 = 15 |
9 + 1 = 10 |
13 (Step 3) |
|
|
【題目16】下列VB語言片斷程式執行後,哪一項是正確的?
Dim a, b
As Integer
a = 1: b
= 2
If (a
> 1) Then → 不成立
a = a + 1
Else
b = b + 2 → 2 + 2 = 4
End If
If (b
> 2) Then → 成立
b = b + 1 → 4 + 1 = 5
Else
a = a + 2
End If
【題目17】執行下列VB語言片段的結果為何?
For i = 1
To 5
s = s + i
Next i
Print s +
i
i |
s = s + i |
i |
s = s + i |
1 |
0 + 1 = 1 |
4 |
6 + 4 = 10 |
2 |
1 + 2 = 3 |
5 |
10 + 5 =15 |
3 |
3 + 3 = 6 |
6 |
15 + 6 = 21 |
【題目18】下列VB程式計算1
+ 2 + 3 + .... + 10
I = 1: SUM
= 0
WHILE I <= 10
SUM = SUM + 1: I = I
+ 1
WEND
請問程式中WHILE右方空格為何者?
I |
I <= 10 |
Sum = Sum + 1 |
I = I + 1 |
I |
I <= 10 |
Sum = Sum + 1 |
I = I + 1 |
1 |
T |
0 + 1 = 1 |
1 + 1 = 2 |
6 |
T |
15 + 6 = 21 |
6 + 1 = 7 |
2 |
T |
1 + 2 = 3 |
2 + 1 = 3 |
7 |
T |
21 + 7 = 28 |
7 + 1 = 8 |
3 |
T |
3 + 3 = 6 |
3 + 1 = 4 |
8 |
T |
28 + 8 = 36 |
8 + 1 = 9 |
4 |
T |
6 + 4 = 10 |
4 + 1 = 5 |
9 |
T |
36 + 9 = 45 |
9 + 1 = 10 |
5 |
T |
10 + 5 = 15 |
5 + 1 = 6 |
10 |
T |
45 + 10 = 55 |
10 + 1 = 11 |
|
|
|
|
11 |
F |
|
|
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。