114 年 國立臺灣大學生物機電系碩士班丁組《計算機概論(A)》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題

Single choice (with single answer) problems. (4% each; 20% in total)

a) Given the following block of C program code. Which line contains an error?
i. int m = 5;
ii. double n = 99;
iii. double o = m;
iv. int p = n;

b) Which of the following is not executed by the BIOS?
i. Memory test
ii. Load application software
iii. Print a test page on the printer
iv. Load the operating system

c) Which of the following is NOT an internet protocol?
i. SMTP
ii. FTP
iii. HTML
iv. HTTP

d) Which of the following statement is not true?
i. Both Turing or von Neumann models has the concept of the program
ii. In the Turing model, the output data depends only on the input data without the program
iii. A universal Turing machine can do any computation if the appropriate program is provided
iv. A program in the von Neumann model is made of a finite number of instructions

e) In which of the following addition problems (using two's complement notation) does an overflow error occur?
i. 1100 + 1100
ii. 1100 + 0100
iii. 0011 + 1010
iv. 0100 + 0100

登入後即可作答並保存紀錄。

這一題的完整詳解

a) C 程式型別轉換

核心觀念

本題考查 C 語言的基本資料型別與型別轉換:

  • int:整數型別。
  • double:倍精度浮點數型別。
  • int 指派給 double 屬於由較小範圍整數轉為浮點數,通常可自動轉換。
  • double 指派給 int 屬於窄化轉換,小數部分可能被截去,且可能造成資料精度或數值範圍損失。

選項分析

i. int m = 5;

宣告整數變數 m,並以整數常數 5 初始化,型別相符,正確。

ii. double n = 99;

整數常數 99 可自動轉換為 double,相當於 99.0,正確。

iii. double o = m;

m 是 int,指派給 double 時會自動進行整數轉浮點數,例如 5 轉為 5.0,正確。

iv. int p = n;

n 是 double,指派給 int 時會進行窄化轉換。若 n 為 99.8,指派後會成為 99;此寫法在標準 C 中通常仍可編譯,但可能產生編譯器警告,基礎教材常將其視為型別不相容錯誤。

解題技巧

看到「浮點數指定給整數」時,優先注意資料遺失問題;反方向的整數指定給浮點數通常是安全的自動轉換。

【答案】iv. int p = n;


b) BIOS 的功能

核心觀念

BIOS(Basic Input/Output System)是電腦開機時執行的韌體,主要負責:

  1. 執行 POST(Power-On Self-Test),檢查硬體。
  2. 測試記憶體與基本輸入輸出裝置。
  3. 尋找開機裝置。
  4. 載入作業系統的開機程式,將控制權交給作業系統。

BIOS 並不負責一般應用程式的載入,也不負責替印表機執行測試列印。

選項分析

i. Memory test

記憶體測試屬於 POST 的一部分,BIOS 會在開機時執行,正確。

ii. Load application software

應用軟體通常由作業系統載入與管理,不是 BIOS 的主要功能,錯誤。

iii. Print a test page on the printer

BIOS 可能初始化基本硬體,但不會在一般開機流程中替印表機列印測試頁,錯誤。

iv. Load the operating system

BIOS 會尋找開機裝置並載入作業系統的 bootloader,接著由 bootloader 載入作業系統,正確。

解題技巧

記住開機層次:

BIOS→Bootloader→作業系統→應用軟體\text{BIOS} \rightarrow \text{Bootloader} \rightarrow \text{作業系統} \rightarrow \text{應用軟體}

因此,應用軟體應由作業系統載入,而非 BIOS。

本題若要求唯一單選,題目本身有兩個不屬於 BIOS 的敘述;依標準定義,ii 與 iii 都不正確。

【答案】ii、iii(題目選項無法形成唯一單選答案)


c) 網際網路協定

核心觀念

網路協定是規範網路設備或程式如何交換資料的規則。常見應用層協定包括:

  • SMTP:傳送電子郵件。
  • FTP:檔案傳輸。
  • HTTP:網頁資料傳輸。

HTML 則是網頁標記語言,用來描述網頁的結構與內容,不是網路通訊協定。

選項分析

i. SMTP

SMTP(Simple Mail Transfer Protocol)是簡易郵件傳送協定,用於寄送電子郵件,屬於網路協定,正確。

ii. FTP

FTP(File Transfer Protocol)是檔案傳輸協定,用於檔案上傳與下載,正確。

iii. HTML

HTML(HyperText Markup Language)是超文字標記語言,不負責規範網路資料傳輸,錯誤。

iv. HTTP

HTTP(HyperText Transfer Protocol)是超文字傳輸協定,瀏覽器通常透過 HTTP 或 HTTPS 取得網頁,正確。

解題技巧

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題10 分

For each row below containing a binary, decimal, and hexadecimal number. Answer the largest value in a row. Provide the number type (binary, decimal, and hexadecimal) in your answer. Answer "All Equal" if all three entries have the same value.

BinaryDecimalHexadecimalAll equal
(a) 1022All equal
(b) 110012CAll Equal
(c) 100101812All Equal
(d) 1000003419All Equal
(e) 1111110250FEAll Equal

登入後即可作答並保存紀錄。

這一題的完整詳解

這是一道關於不同數字表示法之間轉換和比較的題目。需要將每一行的二進位、十進位和十六進位數字轉換成統一的表示法(例如十進位),然後找出該行中最大的值,並註明其原始的數字類型。

核心觀念: 二進位、十進位、十六進位之間的轉換,以及數字大小的比較。

解題步驟:
對於每一行,我們將二進位和十六進位轉換為十進位,然後與原有的十進位值比較,找出最大者。

(a)

  • Binary: 10
    • 10 (二進位) = 1×21+0×20=21 \times 2^1 + 0 \times 2^0 = 2 (十進位)。
  • Decimal: 2
  • Hexadecimal: 2
    • 2 (十六進位) = 2×160=22 \times 16^0 = 2 (十進位)。
  • 比較: 2, 2, 2。
  • 結果: 三者值相等。
  • 【答案】All Equal

(b)

  • Binary: 1100
    • 1100 (二進位) = 1×23+1×22+0×21+0×20=8+4+0+0=121 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 0 \times 2^0 = 8 + 4 + 0 + 0 = 12 (十進位)。
  • Decimal: 12
  • Hexadecimal: C
    • C (十六進位) = 12 (十進位)。
  • 比較: 12, 12, 12。
  • 結果: 三者值相等。
  • 【答案】All Equal

(c)

  • Binary: 10010
    • 10010 (二進位) = 1×24+0×23+0×22+1×21+0×20=16+0+0+2+0=181 \times 2^4 + 0 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 0 \times 2^0 = 16 + 0 + 0 + 2 + 0 = 18 (十進位)。
  • Decimal: 18
  • Hexadecimal: 12
    • 12 (十六進位) = 1×161+2×160=16+2=181 \times 16^1 + 2 \times 16^0 = 16 + 2 = 18 (十進位)。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題10 分

If a 5-minute song is sampled at 44 kHz, and each sample is stored as two 8-bit numbers. How much space in Megabyte it needs to store the song? (10%)

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查數位音訊的儲存容量計算:

資料量=取樣次數×每次取樣的資料量\text{資料量}=\text{取樣次數}\times\text{每次取樣的資料量}

題目給定:

  • 歌曲長度:55 分鐘
  • 取樣率:44 kHz=44,00044\text{ kHz}=44{,}000 次/秒
  • 每次取樣儲存兩個 88-bit 數字

每次取樣的資料量為:

2×8 bits=16 bits=2 bytes2\times 8\text{ bits}=16\text{ bits}=2\text{ bytes}

解題方法

先將歌曲時間換算成秒:

5×60=300 秒5\times 60=300\text{ 秒}

歌曲總取樣次數:

44,000×300=13,200,000 次44{,}000\times 300=13{,}200{,}000\text{ 次}

每次取樣需要 22 bytes,因此總儲存空間為:

13,200,000×2=26,400,000 bytes13{,}200{,}000\times 2 =26{,}400{,}000\text{ bytes}

若題目採十進位定義:

1 MB=1,000,000 bytes1\text{ MB}=1{,}000{,}000\text{ bytes}

則:

26,400,0001,000,000=26.4 MB\frac{26{,}400{,}000}{1{,}000{,}000} =26.4\text{ MB}
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題10 分

Assume that a system that is similar to the IEEE standard. The system uses 8 bits to represent the floating-point. The leftmost bit is the sign bit. The following 3 bits are exponent stored in Excess 3 system. The final 5 bits store the mantissa after normalization.
Decode the following bit patterns into a floating point: (a) 01011001 and (b) 10101100.
(10%)

登入後即可作答並保存紀錄。

這一題的完整詳解

這是一道關於浮點數表示法的題目,要求根據自定義的 8 位元浮點數格式,解碼給定的二進位模式。

核心觀念: 浮點數表示法 (符號位、指數、尾數/ mantissa)、Excess-3 編碼、二進位轉十進位。

自定義浮點數格式:

  • 總位元數:8 bits
  • 符號位 (Sign bit):最左邊 1 bit (0 表示正數,1 表示負數)。
  • 指數 (Exponent):緊跟符號位之後的 3 bits。使用 Excess-3 編碼。
  • 尾數 (Mantissa):最後 5 bits。假設已經正規化 (normalized),且隱含一個前導 1。

Excess-3 編碼:
Excess-3 編碼是一種非加權碼,用於表示數字。對於一個 nn 位元的 Excess-3 碼,其代表的十進位值是將該位元組解讀為二進位後,減去 3。
例如,對於 3 bits 的指數:

  • 000 (binary) -> 0−3=−30 - 3 = -3
  • 001 (binary) -> 1−3=−21 - 3 = -2
  • 010 (binary) -> 2−3=−12 - 3 = -1
  • 011 (binary) -> 3−3=03 - 3 = 0
  • 100 (binary) -> 4−3=14 - 3 = 1
  • 101 (binary) -> 5−3=25 - 3 = 2
  • 110 (binary) -> 6−3=36 - 3 = 3
  • 111 (binary) -> 7−3=47 - 3 = 4

浮點數的標準形式:
浮點數通常表示為:(−1)sign×(1.mantissa)binary×2exponent(-1)^{\text{sign}} \times (1.\text{mantissa})_{\text{binary}} \times 2^{\text{exponent}}
這裡的 1.mantissa 是因為假設尾數已經正規化。

解碼步驟:
對於給定的 8 位元二進位模式,我們將其分割為符號位、指數位和尾數位,然後進行轉換。

(a) 01011001

  1. 分割位元:
    • Sign bit (S):0 (表示正數)

    • Exponent bits (E):101

    • Mantissa bits (M):1001 (注意:題目說最後 5 bits,這裡給了 8 bit,所以 Mantissa 應該是最後 5 bits。原題目應為 01011001,總共 8 bits。那麼 S=0, E=101, M=10010。請注意:題目原文為 01011001,總共 8 bits。所以 S=0, Exponent=101, Mantissa=1001。然而,題目說「final 5 bits store the mantissa」。這表示原題目的位元串可能是 01011001,但 Mantissa 應該是最後 5 bits。這裡的 1001 只有 4 bits。
      仔細閱讀題目: "The final 5 bits store the mantissa"。這意味著給定的 8-bit 串,最後 5 bits 是 Mantissa。
      所以,對於 01011001:

      • S = 0 (1 bit)
      • E = 101 (3 bits)
      • M = 1001 (4 bits)。
        這裡出現矛盾,給定的位元串是 8 bits,但 S+E+M = 1+3+5 = 9 bits。
        假設題目給的位元串是正確的,並且是 8 bits,那麼 Mantissa 應該是最後 4 bits(如果 S=1, E=3, M=4,總共 8 bits)。
        或者,題目給的位元串是 9 bits,但 OCR 掃描成 8 bits?
        最可能的解釋是:題目給的 8 bits 是 S + E + M,但 M 的長度是 5 bits。這意味著 S+E+M 的總長度應該是 1+3+5=9 bits。
        如果題目給的 8 bits 是 S+E+M,則 M 的長度應該是 8-1-3=4 bits。
        題目說 "The final 5 bits store the mantissa"。這表示 M 的長度是 5。
        那 S+E+M = 1 + 3 + 5 = 9 bits。
        這意味著給定的位元串 (a) 01011001 和 (b) 10101100 都是 8 bits,但它們的結構是 S(1 bit) + E(3 bits) + M(5 bits)。
        這表示 S+E+M 總長度是 9 bits。
        這是一個明顯的矛盾。

      我將假設題目給的 8-bit 串是有效的,並且 S=1 bit, E=3 bits, M=4 bits (8-1-3=4)。
      如果 M 是 5 bits,那 8-bit 串就無法包含 S, E, M。
      我將按照「最後 5 bits 是 Mantissa」的敘述,推測題目給的 8-bit 串可能 OCR 有誤,或者它其實是一個 9-bit 串被截斷了。
      如果我們嚴格按照「8 bits」來解析,那麼 M 必定是 4 bits。
      但題目又明確說 "The final 5 bits store the mantissa"。

      我將採用一種折衷的解釋:
      假設給定的 8-bit 串是 S(1 bit) + E(3 bits) + M(4 bits),並且題目關於 M 是 5 bits 的描述是錯誤的。
      或者,假設 S(1 bit) + E(3 bits) + M(5 bits) 是標準,那麼給定的 8-bit 串是 S+E+M 的前 8 bits,或是 S+E+M 的某 8 bits。

      讓我們嘗試另一種解釋:
      題目說 "The system uses 8 bits to represent the floating-point"。這 8 bits 是 S + E + M 的總和。
      "The leftmost bit is the sign bit." (1 bit)
      "The following 3 bits are exponent" (3 bits)
      "The final 5 bits store the mantissa" (5 bits)
      這三部分加起來是 1 + 3 + 5 = 9 bits。這與「uses 8 bits」矛盾。

      我將假設題目意圖是 S(1) + E(3) + M(4) = 8 bits。
      並忽略「final 5 bits」的描述,或者認為那是一個印刷錯誤。
      如果 M 是 4 bits,那麼正規化後的尾數是 1.M1.M。

      (a) 01011001 (8 bits)

      • S = 0 (正)
      • E = 101 (3 bits)
      • M = 1001 (4 bits)

      將 Exponent bits 101 轉換為十進位並應用 Excess-3:

      • 101 (binary) = 1×22+0×21+1×20=4+0+1=51 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 = 4 + 0 + 1 = 5 (decimal)。
      • 實際指數 (Exponent) = 5−3=25 - 3 = 2。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題10 分

Suppose there are three input, inl, in2, and in3. Draw a digital circuit that implements the logical expression: not (not inl and in2) or ((not in2 and in3) or in3)
(10%)

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查布林代數、德摩根定律與吸收律,並要求將邏輯運算式轉換成數位邏輯閘電路。

基本定義如下:

  • NOT:¬A\lnot A
  • AND:A∧BA \land B
  • OR:A∨BA \lor B

題目中的 inl 視為輸入變數 in1in1。原式為:

F=¬(¬in1∧in2)∨((¬in2∧in3)∨in3)F=\lnot(\lnot in1\land in2)\lor\big((\lnot in2\land in3)\lor in3\big)

會用到的定律:

德摩根定律:

¬(A∧B)=¬A∨¬B\lnot(A\land B)=\lnot A\lor\lnot B

吸收律:

A∨(A∧B)=AA\lor(A\land B)=A

解題方法與布林化簡

第一部分:化簡 ¬(¬in1∧in2)\lnot(\lnot in1\land in2)

利用德摩根定律:

¬(¬in1∧in2)=¬(¬in1)∨¬in2\lnot(\lnot in1\land in2) = \lnot(\lnot in1)\lor\lnot in2

由雙重否定律 ¬(¬in1)=in1\lnot(\lnot in1)=in1,得到:

¬(¬in1∧in2)=in1∨¬in2\lnot(\lnot in1\land in2)=in1\lor\lnot in2

第二部分:化簡 (¬in2∧in3)∨in3(\lnot in2\land in3)\lor in3

將式子重新排列:

(¬in2∧in3)∨in3=in3∨(¬in2∧in3)(\lnot in2\land in3)\lor in3 = in3\lor(\lnot in2\land in3)

依吸收律 A∨(A∧B)=AA\lor(A\land B)=A:

in3∨(¬in2∧in3)=in3in3\lor(\lnot in2\land in3)=in3

因此,原式化簡為:

F=(in1∨¬in2)∨in3F=(in1\lor\lnot in2)\lor in3

最後整理為:

F=in1∨¬in2∨in3\boxed{F=in1\lor\lnot in2\lor in3}

數位電路

依原始運算式直接實作

若完全按照題目原式實作,需要:

  1. 對 in1in1、in2in2 分別使用 NOT 閘,產生 ¬in1\lnot in1、¬in2\lnot in2。
  2. 將 ¬in1\lnot in1 與 in2in2 輸入 AND 閘。
  3. 將 AND 閘輸出再輸入 NOT 閘。
  4. 將 ¬in2\lnot in2 與 in3in3 輸入 AND 閘。
  5. 將該 AND 閘輸出與 in3in3 輸入 OR 閘。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 6 題20 分

Show the values of registers R0, R1, R2, R3, and R4 after the each of the instructions in the assembly code below. (20%)

LineInstruction
1MOV R4, #2
2MUL R0, R4, R4
3ADD R1, R4, #1
4SUB R2, R4, #1
5ADD R3, R0, R4

登入後即可作答並保存紀錄。

這一題的完整詳解

這是一道關於組合語言 (Assembly Language) 的題目,要求追蹤寄存器 (Register) 的值在執行一系列指令後如何變化。

核心觀念: 組合語言指令的語義 (MOV, MUL, ADD, SUB),寄存器操作。

寄存器初始值:
題目沒有給出寄存器 R0, R1, R2, R3, R4 的初始值,在這種情況下,我們通常假設它們為 0,或者只關注指令執行後的值。為了清晰起見,我們將展示從指令執行開始,寄存器的值如何更新。

指令集說明:

  • MOV Rd, val:將立即數 val 或寄存器值移動到寄存器 Rd。
  • MUL Rd, Rs, Rt:將寄存器 Rs 和 Rt 的值相乘,結果存入寄存器 Rd。
  • ADD Rd, Rs, Rt:將寄存器 Rs 和 Rt 的值相加,結果存入寄存器 Rd。
  • SUB Rd, Rs, Rt:將寄存器 Rs 的值減去寄存器 Rt 的值,結果存入寄存器 Rd。

追蹤寄存器值:

| Line | Instruction | R0 | R1 | R2 | R3 | R4 | 說明 |

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 7 題20 分

The follow is a function to raise grades written in C language. The function calls another function named "sort" to sort grades in ascending order. Identify each buggy line in the program. Explain the bugs concisely. You may either explain the bug without fixing it, or provide a snippet of code that would correct it. You do not need to write complete sentences or complete corrected lines of code. (20%)

public void inflateGrades (int[] studentGrades) {
    int[] copyOfGrades = int[studentGrades.length];
    // copy the contents of studentGrades 1 at a time
    copyOfGrades = studentGrades;
    copyOfGrades = sort(copyOfGrades);
    // for each grade in student grades...
    for (int i = 0; i <= studentGrades.length; i++) {
        // if student has maximum grade, give 100
        if (studentGrades[i] == copyOfGrades[0]) {
            studentGrades[i] = 100;
            break;
        }
    }
    // otherwise find the next grade after toBeFound
    int toBeFound = studentGrades[j]; // Potential bug here due to j
    for (int j = 0; j <= studentGrades.length; j++) {
        if (toBeFound == copyOfGrades[j]) {
            while(toBeFound == copyOfGrades[j])
                studentGrades[j] = copyOfGrades[j]; // Possible issue with this line
            j--; // Possible issue with j manipulation
        }
    }
}
public static void sort(int[] array) {
    for (int i = 0; i < array.length - 1; i++) {
        int a = array[i];
        int b = i;
        for (int j = i + 1; j < array.length; j++) {
            if (array[j] < a) {
                a = array[j];
                b = j;
            }
        }
        // Swap logic is missing here
        int temp = array[i];
        array[i] = array[b];
        array[b] = temp;
        printArray(array); // Assuming printArray exists
    }
}

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題主要考查:

  • 陣列配置與索引範圍:長度為 nn 的陣列,合法索引為 00 到 n−1n-1。
  • 陣列複製與參照別名(aliasing)。
  • 方法回傳型別與呼叫方式。
  • 變數作用域(scope)。
  • while 迴圈的終止條件與索引更新。
  • 選擇排序法(selection sort)。
  • 排序後最小值與最大值的位置。

解題方法

逐行檢查下列項目:

  1. 程式是否符合語言語法與型別規則。
  2. 陣列索引是否可能超出範圍。
  3. 排序結果是否破壞原始資料。
  4. 迴圈是否一定能結束。
  5. 程式實際執行結果是否符合註解與題意。

逐行錯誤分析

1. 程式語言與函式宣告不一致

題目文字稱為 C 語言,但程式使用:

public void inflateGrades (int[] studentGrades)

以及:

int[]
public static void

這是 Java 風格,不是合法的標準 C 語法。

若按照 Java 程式分析,以下各項是主要錯誤;若按照 C 語言實作,陣列宣告、記憶體配置與函式語法都必須全面改寫。


2. 陣列配置語法錯誤

int[] copyOfGrades = int[studentGrades.length];

Java 建立陣列必須使用 new:

int[] copyOfGrades = new int[studentGrades.length];

原程式缺少 new,無法通過編譯。


3. 沒有複製陣列內容,只是複製參照

copyOfGrades = studentGrades;

這行不會逐一複製元素,而是讓兩個變數指向同一個陣列。

因此:

copyOfGrades[i] = ...

等同於修改:

studentGrades[i]

正確的陣列複製方式可寫成:

int[] copyOfGrades = studentGrades.clone();

或:

int[] copyOfGrades = Arrays.copyOf(studentGrades, studentGrades.length);

4. sort 的回傳型別與呼叫方式不符

copyOfGrades = sort(copyOfGrades);

但 sort 宣告為:

public static void sort(int[] array)

void 函式沒有回傳值,因此不能指定給 copyOfGrades。

若採用原本的就地排序方式,應寫成:

sort(copyOfGrades);

若要保留原本的指定寫法,則必須將 sort 改成回傳陣列:

public static int[] sort(int[] array) {
    ...
    return array;
}

5. 排序的別名問題會破壞原始成績

即使修正 sort 的回傳型別,原本已有:

copyOfGrades = studentGrades;

所以 sort(copyOfGrades) 實際上也會直接排序 studentGrades。

這會使原始成績順序被改變,違反「使用副本排序」的意圖。

正確順序應為:

int[] copyOfGrades = studentGrades.clone();
sort(copyOfGrades);

6. 第一個 for 迴圈的索引條件錯誤

for (int i = 0; i <= studentGrades.length; i++)

陣列長度為 nn 時,最後合法索引是 n−1n-1。當 i == studentGrades.length 時,會存取不存在的元素:

studentGrades[i]

因此應改為:

for (int i = 0; i < studentGrades.length; i++)

7. 使用排序陣列的錯誤端點尋找最高分

if (studentGrades[i] == copyOfGrades[0])

題目註解表示要找最大成績,但排序是遞增排序:

copyOfGrades[0]≤copyOfGrades[1]≤⋯≤copyOfGrades[n−1]copyOfGrades[0] \le copyOfGrades[1] \le \cdots \le copyOfGrades[n-1]

所以:

  • 最小值位於 copyOfGrades[0]
  • 最大值位於 copyOfGrades[studentGrades.length - 1]

若要找最高分,應寫成:

if (studentGrades[i] == copyOfGrades[copyOfGrades.length - 1])

8. break 只處理第一位最高分學生

studentGrades[i] = 100;
break;

這會在找到第一個符合條件的成績後立即離開迴圈。

若題意是「只把一位最高分學生調整為 100」,break 可以保留。若題意是「所有並列最高分的學生都調整為 100」,則不應使用 break。

此處是否為錯誤,取決於「最高分學生」是指一人或所有並列者;但程式註解使用單數,通常可解讀為只處理一位。


9. j 尚未宣告即被使用

int toBeFound = studentGrades[j];

此處的 j 尚未宣告。後面的:

for (int j = 0; ...)

只在該 for 迴圈內有效,不能用於前一行。

這會造成編譯錯誤。

應先明確宣告並初始化索引,例如:

int j = 0;
int toBeFound = studentGrades[j];
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題