糯米文學吧

位置:首頁 > 計算機 > 計算機二級

2014計算機二級C語言程序設計真題試題及答案(word版)

#include

2014計算機二級C語言程序設計真題試題及答案(word版)

#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("nn%d=%d+%dn",num,b,c);

}

}

請編寫函數proc(),其功能是:將str所指字符串中除下標為偶數,同時ASCII碼值為奇數的字符外,其餘的字符都刪除,串中剩餘字符所 形成的一個新串放在t所指的數組中。例如,若str所指字符串中的內容為ABCDEFG12345,其中字符8的ASCII碼值為偶數,所在元素的下標為 奇數,因此必須刪除;而字符A的I碼值為奇數,所在數組中的下標為偶數,因此不應當刪除。依此類推,最後t所指的數組中的內容應是ACEG。

注意:部分源程序給出如下。

請勿改動main()函數和其他函數中的任何內容,僅在函數proc()的花括號中填入所寫的若干語句。

試題程序:

#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:%sn",t);

}

請補充main()函數,該函數的功能是:從鍵盤輸入一組字符串,以“*”結束輸入,並顯示出這個字符串。

例如,輸入ABCDEFG*,結果顯示ABCDEFG。