當前位置:才華齋>英語>等級考試>

2014年計算機等級考試C語言衝刺題(程式填空題)

等級考試 閱讀(8.69K)

 衝刺題一

2014年計算機等級考試C語言衝刺題(程式填空題)

請補充main()函式,該函式的功能是:輸入兩個正整數numl和num2,求這兩個數的最大公約數和最小公倍數。

例如,若輸人的兩個正整數為12,4,則它們的最大公約數為4,最小公倍數為12。

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

請勿改動main()函式和其他函式中的任何內容,僅在main()函式的橫線上填入所編寫的若干表示式或語句。

試題程式:

#include

#include

void main()

{

int a,b,numl,num2,t;

system(”CLS”):

printf(”nlnput tWO numbers:n”);

scanf(”%d,%d”,&numl,&num2);

if(numl {

a=num2;

b=numl;

}

else

{

a=num1:

b=num2:

)

while(【1】)

{

t=【2】

a=b;

b=t;

}

printf("greatest common divisor:

%dn”,a);

printf(”least common multiple:

%dn”,【3】);

衝刺題二

請補充函式proc(),其功能是:計算並輸出給定10個數的方差。

例如,拾定的10個數為12.0,,5.0,6.0,31.0,9.0,3.0,8.0,18、0,輸出為s=8.8771500。

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

請勿改動main()函式和其他函式中的任何內容,僅在函式proc()的橫線上填入所編寫的若於表示式或語句。

試題程式:

#include

#include

double proc(double xElO])

{

int i;

double avg=0.0;

double 8urn=0.0;

double abs=0.0:

double sd;

for(i=0:i<10;i++)

【1】 ;

avg=sum/10;

for(i=0;i<10;i十十)

【2】 ;

sd= 【3】 ;

return sd;

void main()

{

double s,str[10]={12.0,9.0,26.0,5.0,6.0,31.0.

9.0,3.0,8.0,18.0);

int i;

printf(”nThe original data is:n”);

for(i一0;i<10;i++)

t)rintf(”%,slr[i]):

printf(”nn”);

s=proc(str):

printf(”s=%fnn”,s);

)

衝刺題三

請補充main()函式,該函式的功能是:把一個字串中的所有小寫字母字元全部轉換成大寫字母字元,其他字元不變,結果儲存在原來的字串中。

例如,當str[M]=”abcdefl23ABCD”,結果輸出:“ABC

DEF123ABCD”。

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

請勿改動main()函式和其他函式中的任何內容,僅在橫線上填入所編寫的`若干表示式或語句。

試題程式:

#include

#include

#include

#define M 80

void main()

{

intj;

char str[M]=" abcdefl23ABCD”;

char *pf=str;

system(”CLS”):

printf(”***original string *** n”):

puts(str);

【1】

while(*(pf+j))

{

if(*(pf+j)>='a' &&*(pf+j)<='Z')

{

*(pf+j)=【2】 ;

【3】 ;

)

else

j++;

)

printf(”****new string****n”);

puts(str);

system(”pause”);}

衝刺題四

str是一個由數字和字母字元組成的字串,由變數num傳人字串長度。請補充函式proc(),該函式的功能是:把字串str中的數字字元轉換成數字並存放到整型陣列1,b中,函式返回陣列bh的長度。

例如=”abc123de45f967”.結果為:1234567。

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

請勿改動main()函式和其他函式中的任何內容.僅在函式proc()的橫線上填入所編寫的若干表示式或語句。

試題程式:

#include

#define M 80

int bb[M];

int proc(char str[] bh[],int num)

{

int i.n=0;

for(i=0;i {

if( 【1】 )

{

bb[n]=【2】;

n++:

)

return 【3】 ;

}

void main()

{

char str[M];

int num=0.n,i:

printf(”Enter a string:n”);

gets(str);

while(str[num])

num++o

n=proc(str,bb,num);

prinlf(”nbb=”);

for(i=0;i printf(”%d”,bb[i]);

)