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

字號:

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

    3、給定程序中,函數(shù)fun的功能是:將N×N矩陣主對角線元素中的值與反向?qū)蔷€對應(yīng)位置上元素中的值進(jìn)行交換。例如,若N=3,有下列矩陣:
    1 2 3
    4 5 6
    7 8 9交換后為:
    3 2 1
    4 5 6
    9 8 7
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    #define N 4
    /**********found**********/
    void fun(int ___1___ , int n)
    { int i,s;
    /**********found**********/
    for(___2___; i++)
    { s=t[i][i];
    t[i][i]=t[i][n-i-1];
    /**********found**********/
    t[i][n-1-i]=___3___;
    }
    }
    main()
    { int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j;
    printf("\nThe original array:\n");
    for(i=0; i
    { for(j=0; j
    }
    fun(t,N);
    printf("\nThe result is:\n");
    for(i=0; i
    { for(j=0; j
    }
    }
    4、給定程序中,函數(shù)fun的功能是:找出100至x(x≤999)之間各位上的數(shù)字之和為15的所有整數(shù),然后輸出;符合條件的整數(shù)個數(shù)作為函數(shù)值返回。
    例如,當(dāng)n值為500時,各位數(shù)字之和為15的整數(shù)有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有26個。
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    int fun(int x)
    { int n, s1, s2, s3, t;
    /**********found**********/
    n=__1__;
    t=100;
    /**********found**********/
    while(t<=__2__)
    { s1=t%10; s2=(t/10)%10; s3=t/100;
    if(s1+s2+s3==15)
    { printf("%d ",t);
    n++;
    }
    /**********found**********/
    __3__;
    }
    return n;
    }
    main()
    { int x=-1;
    while(x>999||x<0)
    { printf("Please input(0
    printf("\nThe result is: %d\n",fun(x));
    }
    5、函數(shù)fun的功能是:把形參a所指數(shù)組中的最小值放在元素a[0]中,接著把形參a所指數(shù)組中的值放在a[1]元素中;再把a所指數(shù)組元素中的次小值放在a[2]中,把a所指數(shù)組元素中的次大值放在a[3];其余以此類推。例如:若a所指數(shù)組中的數(shù)據(jù)最初排列為:9、1、4、2、3、6、5、8、7;則按規(guī)則移動后,數(shù)據(jù)排列為:1、9、2、8、3、7、4、6、5。形參n中存放a所指數(shù)組中數(shù)據(jù)的個數(shù)。
    注意:規(guī)定fun函數(shù)中的max存放當(dāng)前所找的值,px存放當(dāng)前所找值的下標(biāo)。
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    # include
    #define N 9
    void fun(int a[], int n)
    { int i,j, max, min, px, pn, t;
    for (i=0; i
    {
    /**********found**********/
    max = min = ___1___;
    px = pn = i;
    for (j=i+1; j
    /**********found**********/
    if (max<___2___)
    { max = a[j]; px = j; }
    /**********found**********/
    if (min>___3___)
    { min = a[j]; pn = j; }
    }
    if (pn != i)
    { t = a[i]; a[i] = min; a[pn] = t;
    if (px == i) px =pn;
    }
    if (px != i+1)
    { t = a[i+1]; a[i+1] = max; a[px] = t; }
    }
    }
    main()
    { int b[N]={9,1,4,2,3,6,5,8,7}, i;
    printf("\nThe original data :\n");
    for (i=0; i
    fun(b, N);
    printf("\nThe data after moving :\n");
    for (i=0; i
    }