2014年3月計算機二級考試真題:C語言程序設(shè)計(網(wǎng)友版)

字號:


    
全國計算機等級考試熱點-備考方案
報名時間 考試時間 成績查詢 考試真題 考試試題 收藏本站
不斷更新中......敬請期待?。∮嬎銠C等級考試頻道

    12、以下只有在使用時才為該類型變量分配內(nèi)存的存儲類型說明是( )。
    A.a(chǎn)ut0和static B.a(chǎn)uto和register
    C.register和static D.extern和register
    5、若fp是指向某文件的指針,且尚未讀到文件末尾,則函數(shù)feof(fp)的返回值是(?。?BR>    A.EOF B.-1 C.非零值 D.0
    1、數(shù)據(jù)庫DB、數(shù)據(jù)庫系統(tǒng)DBS、數(shù)據(jù)庫管理系統(tǒng)DBMS之間的關(guān)系是( )。
    A.DB包含DBS和DBMS B.DBMS包含DB和DBS
    C.DBS包含DB和DBMS D.沒有任何關(guān)系
    2、有下列程序: fun(int x,int y){return(x+y);) main() (int a=1,b=2,c=3,sHm; sum=fun((a++,b++,a+b),c++); printf(”%d\n”,sum); ) 執(zhí)行后的輸出結(jié)果是(?。?BR>    A.6 B.7 C.8 D.9
    請補充函數(shù)proe(),該函數(shù)的功能是:按’0’到’9’統(tǒng)計一個字符串中的奇數(shù)數(shù)字字符各自出現(xiàn)的次數(shù),結(jié)果保存在數(shù)組mum中(注意:不能使用字符串庫函數(shù))。
    例如,輸入“x=1581453927843770hfds574",結(jié)果為:1=2,3=2,5=3,7=4,9=1。
    注意:部分源程序給出如下。
    請勿改動main()函數(shù)和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)proc()的橫線上填入所編寫的若干表達(dá)式或語句。
    試題程序:
    #include
    #include
    #define M 1000
    void proc(char*str,int num[])
    {
     int i,j;
     int bb[10];
     char*p=str;
     for(i=0;i<10;i++)
     {
     num[i]=0;
     bb[iJ=0;
     }
     while(【1】)
     {
     if(*p>=’0’&&*p<=’9’)
     【2】 ;
     p++;
     }
     for(i=1,j=0;i<10;i=i+2,j++)
     【3】 ;
    }   void main()
    {
     char str[M];    int num[10],k;
     system("CLS");
     printf("\nPlease enter a char string:");
     gets(str);
     printf("\n**The original string**\n");
     puts(str);
     proc(str,num);
     printf("\n**The number of letter**\n");
     for(k=0;k<5;k++)
     {
     printf("\n");
     printf("%d=%d",2*k+1,num[k]);
     }
     printf("\n");
    }
    下列給定的程序中,函數(shù)proc()的功能是:為一個偶尋找兩個素數(shù),這兩個素數(shù)之和等于該偶數(shù),并將這兩個數(shù)通過形參指針傳回主函數(shù)。
    請修改函數(shù)proc()中的錯誤,使它能得出正確的結(jié)果
    注意:不要改動main()函數(shù),不得增行或刪行,也不更改程序的結(jié)構(gòu)。   試題程序:
    #include
    #include
    void proc(int num,int*b,int*c)
    {
     int i,j,d,y;
     for(i=3;i<=num/2;i=i+2)
     //****found****
     { y=0;
     for(j=2;j<=sqrt((double)i);j++)
     if(i%j==0)y=0;
     if(y==l)
     //****found****
     { d=i-num;
     for(j=2;j<=sqrt((double)d);    j++)
     if(d%j==0)y=0;
     if(y==l)
     {*b=i;*c=d;)
     }
     }
    }   void main()
    { int mum,b,C;
     do
     { printf("\nlnput num:");
     scanf("%d",&num);)
     while(num%2); ’
     proc(num,&b,&c);
     printf("\n\n%d=%d+%d\n",num,b,c);
     }
    }
    編寫函數(shù)int proc(int lim,int aa[M]),該函數(shù)的功能是求出小于或等于lim的所有素數(shù)并放在aa數(shù)組中,該函數(shù)返回所求出的素數(shù)。
    例如,若輸人12時,則輸出:2 3 5 7 11。
    注意:部分源程序給出如下。
    請勿改動main()函數(shù)和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)proc()的花括號中填入所編寫的若干語句。   試題程序:
    #include
    #include
    #include
    #define M 1OO
    int proc(int lira,int aa[M])
    {
    }
    void main()
    {
     int limit,i,sum;
     int arr[M];
     system("CLS"):
     printf("輸入一個整數(shù)");
     scanf("%d",&limit);
     sum=proc(limit,arr):
     for(i=0;i  
    {    if(i%10==0&&i!一O)//每行輸出10個數(shù)
     printf("\n");
     printf("%5d",arr[i]);
    }
    }