當前位置:才華齋>計算機>計算機二級>

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

計算機二級 閱讀(1.94W)

#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。