2010計算機等考二級C:50套上機程序填空題(10)

字號:

2010計算機等考二級C:50套上機程序填空題(10)

    19、給定程序中,函數(shù)fun的功能是:將a所指4×3矩陣中第k行的元素與第0行元素交換。
    例如,有下列矩陣:
    1 2 3
    4 5 6
    7 8 9
    10 11 12
    若k為2,程序執(zhí)行結(jié)果為:
    7 8 9
    4 5 6
    1 2 3
    10 11 12
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    #define N 3
    #define M 4
    /**********found**********/
    void fun(int (*a)[N], int __1__)
    { int i,temp ;
    /**********found**********/
    for(i = 0 ; i < __2__ ; i++)
    { temp=a[0][i] ;
    /**********found**********/
    a[0][i] = __3__ ;
    a[k][i] = temp ;
    }
    }
    main()
    { int x[M][N]={ {1,2,3},{4,5,6},{7,8,9},{10,11,12} },i,j;
    printf("The array before moving:\n\n");
    for(i=0; i
    { for(j=0; j
    printf("\n\n");
    }
    fun(x,2);
    printf("The array after moving:\n\n");
    for(i=0; i
    { for(j=0; j
    printf("\n\n");
    }
    }
    20、函數(shù)fun的功能是:將形參a所指數(shù)組中的前半部分元素中的值和后半部分元素中的值對換。形參n中存放數(shù)組中數(shù)據(jù)的個數(shù),若n為奇數(shù),則中間的元素不動。例如:若a所指數(shù)組中的數(shù)據(jù)依次為:1、2、3、4、5、6、7、8、9,則調(diào)換后為:6、7、8、9、5、1、2、3、4。
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    #define N 9
    void fun(int a[], int n)
    { int i, t, p;
    /**********found**********/
    p = (n%2==0)?n/2:n/2+___1___;
    for (i=0; i
    {
    t=a[i];
    /**********found**********/
    a[i] = a[p+___2___];
    /**********found**********/
    ___3___ = t;
    }
    }
    main()
    { int b[N]={1,2,3,4,5,6,7,8,9}, i;
    printf("\nThe original data :\n");
    for (i=0; i
    fun(b, N);
    printf("\nThe data after moving :\n");
    for (i=0; i
    }