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

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

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

  1. (10%) What value will the following code display?

    // Matrix multiplication
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
    const int I=2;
    const int J=3;
    const int K=2;
    int a[I][J] = { { 1, 2, 3 }, { 4, 5, 6 } }
    int b[J][K] = { {1,2},{3,4},{5,6}};
    int c[J][K]={0};
    int i,j,k;

    for (i=0; i<I; i++)
    for (k=0; k<K; k++)
    for (j=0; j<J; j++)
    c[i][k] += a[i][j]*b[j][k];
    for (i=0; i<I; i++)
    {
    for (k=0; k<K; k++)
    cout << c[i][k] << " ";
    cout << 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()
    {
    char msg[2][5] = { "NCNU", "DAY" };
    cout << msg[1][1];
    cout << msg[1];
    }




  3. (10%) What will the following code display?

    // Fibonacci sequence
    #include <iostream>
    using std::cout;
    using std::endl;

    int main()
    {
        int n = 0;
        const int M = 10;
        int F[M] = {0, 1};

        for (n=2; n<M; n++)
                F[n] = F[n-1] + F[n-2];

        for (n=0; n<M; n++)
                cout << F[n] << " ";
        cout << endl;

        cout << "F[6]/F[5]=" << F[6]/F[5] << endl;
    }