國立暨南國際大學 97 學年度第一學期小考試卷

科目名稱:資訊系統 與網路導論 開課系所:資訊工程 學系 任課教師
吳坤熹
系所別:
年級:
學號:
姓名:
考試日期
2008.12.3

(考試時間: 14:10-14:30)

  1. (10%) What value will the following code display?
    #include <iostream>
    using std::cout;
    using std::endl;
    int main() // Bubble Sort
    {
    int i, j, temp;
    int a[] = { 1, 9, 6, 3};
    const int K = sizeof(a) / sizeof(a[0]);
    for (i=0; i<K; i++)
    for (j=K-1; j>i; j--)
    if (a[j-1] > a[j])
    {
    temp = a[j-1];
    a[j-1] = a[j];
    a[j] = temp;
    }
    for (i=0; i<K; i++)
    cout << a[i] << endl;
    }




  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    #include <iostream>
    using std::cout;
    using std::endl;
    int main()
    {
    const int N = 2;
    int i, j, k;
    int a[N][N] = { {1, 2}, {3, 4} };
    int b[N][N] = { {5, 6}, {7, 8} };
    int c[N][N] = { 0 };

    for (i=0; i<N; i++)
    for (j=0; j<N; j++)
    for (k=0; k<N; k++)
    c[i][j] += a[i][k]*b[k][j];

    for (i=0; i<N; i++)
    {
    for (j=0; j<N; j++)
    cout << c[i][j] << "\t";
    cout << endl;
    }
    }