2014計(jì)算機(jī)二級(jí)C語言真題及答案

字號(hào):

#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);
    }
    }
    請(qǐng)編寫函數(shù)proc(),其功能是:將str所指字符串中除下標(biāo)為偶數(shù),同時(shí)ASCII碼值為奇數(shù)的字符外,其余的字符都刪除,串中剩余字符所 形成的一個(gè)新串放在t所指的數(shù)組中。例如,若str所指字符串中的內(nèi)容為ABCDEFG12345,其中字符8的ASCII碼值為偶數(shù),所在元素的下標(biāo)為 奇數(shù),因此必須刪除;而字符A的ASCII碼值為奇數(shù),所在數(shù)組中的下標(biāo)為偶數(shù),因此不應(yīng)當(dāng)刪除。依此類推,最后t所指的數(shù)組中的內(nèi)容應(yīng)是ACEG。
    注意:部分源程序給出如下。
    請(qǐng)勿改動(dòng)main()函數(shù)和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)proc()的花括號(hào)中填入所寫的若干語句。
    試題程序:
    #include
    #include
    #include
    #include
    void proc(char*str,char t[])
    {
    }
    void main()
    {
    char str[100],t[100];
    system("CLS"):
    printf("\nPlease enter string str:");
    scanf("%s",str);
    proc(str,t);
    printf("\nThe result is:%s\n",t);
    }
    請(qǐng)補(bǔ)充main()函數(shù),該函數(shù)的功能是:從鍵盤輸入一組字符串,以“*”結(jié)束輸入,并顯示出這個(gè)字符串。
    例如,輸入ABCDEFG*,結(jié)果顯示ABCDEFG。