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

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

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


  1. (10%) Determine whether the following code has syntax erros or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    #include <iostream>

    using std::cout;

    struct Euclidean
    {
    int M, D, Q, R, A, B;
    };


    void dout(int n)
    {
    if(n<0)
    cout << "(" << n << ")";
    else
    cout << n;
    }

    int main()
    {
    Euclidean E[10];
    int temp1 = 0, temp2 = 0;
    E[0].M = 1003; E[0].D = 590;
    int i = 0;

    do
    {
    E[i].Q = E[i].M / E[i].D;
    E[i].R = E[i].M - E[i].Q * E[i].D;
    E[i+1].M = E[i].D;
    E[i+1].D = E[i].R;
    } while (E[i++].R>0);

    i-=2; E[i].A = 1; E[i].B = -E[i].Q;
    cout << E[i].R;

    while (1)
    {
    cout << "\t=\t"; dout(E[i].A);
    cout << "*"; dout(E[i].M);
    cout << "+"; dout(E[i].B);
    cout << "*"; dout(E[i].D);
    cout << "\n";

    if (i==0) break;
    E[i-1].A = E[i].B;
    E[i-1].B = E[i].A - E[i].B*E[i-1].Q;
    i--;
    }
    }