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

字號:

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

    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存放當前所找的值,px存放當前所找值的下標。
    請在程序的下劃線處填入正確的內(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
    }
    6、給定程序中,函數(shù)fun的功能是:對形參s所指字符串中下標為奇數(shù)的字符按ASCII碼大小遞增排序,并將排序后下標為奇數(shù)的字符取出,存入形參p所指字符數(shù)組中,形成一個新串。
    例如,形參s所指的字符串為:baawrskjghzlicda,執(zhí)行后p所指字符數(shù)組中的字符串應(yīng)為:aachjlsw。
    請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    void fun(char *s, char *p)
    { int i, j, n, x, t;
    n=0;
    for(i=0; s[i]!='\0'; i++) n++;
    for(i=1; i
    /**********found**********/
    ___1___;
    /**********found**********/
    for(j=___2___+2 ; j
    if(s[t]>s[j]) t=j;
    if(t!=i)
    { x=s[i]; s[i]=s[t]; s[t]=x; }
    }
    for(i=1,j=0; i
    /**********found**********/
    p[j]=___3___;
    }
    main()
    { char s[80]="baawrskjghzlicda", p[50];
    printf("\nThe original string is : %s\n",s);
    fun(s,p);
    printf("\nThe result is : %s\n",p);
    }