2017計算機二級C語言上機最終預測題

來源:文萃谷 1.5W

2017年上半年計算機二級考試即將到來,為了幫助大家備考,本站小編整理了計算機二級C語言上機最終預測題,希望幫助大家順利通過計算機二級考試。

2017計算機二級C語言上機最終預測題

  填空題

請補充fun函數,該函數的功能是判斷一個數的個位數字和百位數字之和是否等於其十位上的數字,是則返回“yes!“,是否返回”no!”.

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

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

試題程序:

#include

#include

char *fun(int n)

{

int g, s, b;

g = n%10;

s = n/10%10;

b = ___1___;

if ((g+b) == s)

return ___2___;

else

return ___3___;

}

main()

{

int num = 0;

printf("******Input data *******n ");

scanf("%d", &num);

printf("nnn");

printf("****** The result *******n ");

printf("nnn%s", fun(num));

}

第1處填空:n/100%10

第2處填空:”yes!”

第3處填空:”no!”

  改錯題

下列給定程序中,函數fun的功能是:通過某種方式實現兩個變量值的交換,規定下允許增加語句和表達式。例如變量a中的值原為8,b中的值原為3,程序運行後a中的值為3,b的值為8。

請改正程序中的.錯誤,使其能得出正確結果。

注意:不要改動main函數,不得增行或刪行,也不得更改程序的結構!

試題 程序:

#include

#include

int fun(int *x, int y)

{

int t;

/********found********/

t = x; x = y;

/********found********/

return (y);

}

main()

{

int a = 3, b = 8;

printf("%d %dn", a, b);

b = fun(&a, b);

printf("%d %dn", a, b);

}

第1處:t=x;x=y;應改為t=*x;*x=y;

第2處:return(y);應改為return(t);或return t;

  編程題

請編寫函數FUN,它的功能是:求出SS所指字符串中指定字符的個數,並返回此值。

例如,若輸入字符串123412132,輸入字符1,則輸出3。

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

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

試題程序:#include

#include

#include

#define M 81

int fun(char *ss, char c)

{

}

main()

{

char a[M], ch;

FILE *out;

printf("nPlease enter a string:");

gets(a);

printf("nPlease enter a char:");

ch = getchar();

printf("nThe number of the char is: %dn", fun(a, ch));

out=fopen ("", "w");

strcpy(a, "The number of the char is: ");

fprintf(out, "%d", fun(a, ' '));

fclose (out );

}

答案是:int fun(char *ss,char c)

{

int n=0;

while(*ss)

{

if(*ss==c)

n++;

ss++;

}

return n;

}

熱門標籤