![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
全國等級考試二級C語言2009上機(jī)模擬4 |
一、填空題 請補(bǔ)充函數(shù)fun(char *t),該函數(shù)的功能是把字符串中的內(nèi)容逆置。 例如,字符串中原有的字符串為ABCDE,則調(diào)用該函數(shù)后,串中的內(nèi)容為EDCBA。 請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達(dá)式或語句。 注意:部分源程序給出如下。 # include # include # include # define M 60 void fun(char *t) { int j,m=strlen(t)-1; char s; for(j=0;j s=t[j]; ___2___; ___3___; } } main() { char b[M]; printf("Input a string:"); gets(b); printf("The original string is:"); puts(b); fun(b); printf("\n"); printf("The reversal string :"); puts(b); } 二、改錯題 下列給定程序中,函數(shù)fun的功能是:判斷字符ch是否與s所指串中的某個字符相同,若相同,則什么也不做;若不同,則將其插在串的最后。 請修改程序中的錯誤,使它能得出正確的操作。 注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。 # include # include # include /*******error*********/ void fun(char s,char c) { while(*s && *s!=c) s++; /*******error*********/ if(*s=='c') { s[0]=c; /*******error*********/ s[1]='0'; } } main() { char str[81],ch; printf("\n Please enter a string:\n"); gets(str); printf("\n Please enter the character to search:"); ch=getchar(); fun(str,ch); printf("\nThe result is %s\n",str); } 三、編程題 請編寫函數(shù)fun,函數(shù)的功能是求出二維數(shù)組周邊元素之和,作為函數(shù)值返回。二維數(shù)組中的值在主函數(shù)中賦予。 例如,若二維數(shù)組中的值為: 3 5 7 9 9 9 9 4 9 9 9 8 則函數(shù)值為72。 請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。 注意:部分源程序給出如下。 # include # include # define M 3 # define N 4 int fun(int b[M][N]) { } main() { int a[M][N]={{3,5,7,9},{9,9,9,4}, {9,9,9,8}}; int i,j,sum; FILE *out; printf("The original data is : \n"); for(i=0;i for(j=0;j printf("\n"); } sum=fun(a); printf("\nThe sum: %d\n",sum); printf("\n"); out=fopen("outfile.dat","w"); fprintf(out,"%d",sum); fclose(out); } |