![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
江蘇省全國計(jì)算機(jī)等級(jí)考試二級(jí)C語言2009上機(jī)模擬5 |
一、填空題 請(qǐng)補(bǔ)充main函數(shù),該函數(shù)的功能是:從鍵盤輸入一個(gè)長整數(shù),如果這個(gè)數(shù)是負(fù)數(shù),則取它的絕對(duì)值,并顯示出來。例如,輸入:-666,結(jié)果為:666。 僅在橫線上填寫所需的若干表達(dá)式或語句,請(qǐng)勿改動(dòng)函數(shù)中的其他任何內(nèi)容。 注意:部分源程序給出如下。 # include # include main() { long int a; printf("Enter the data:\n"); scanf(___1___); printf("The origial data is %ld\n",a); if(a<0) ___2___; printf("\n"); printf(___3___); } 二、改錯(cuò)題 下列給定程序中函數(shù)fun的功能是:求出在字符串中最后一次出現(xiàn)的子字符串的地址,通過函數(shù)值返回,在主函數(shù)中輸出從此地址開始的字符串;若未找到,則函數(shù)值為NULL。 例如,當(dāng)字符串中的內(nèi)容為abcdabfabcdx,t中的內(nèi)容為ab時(shí),輸出結(jié)果應(yīng)是:abcdx。當(dāng)字符串中的內(nèi)容為abcdabfabcdx,t中的內(nèi)容為abd時(shí),則程序輸出未找到信息"not found!"。 請(qǐng)修改程序中的錯(cuò)誤,使程序能得出正確的結(jié)果。 注意:不要改動(dòng)main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。 # include # include # include char *fun(char *str,char *t) { char *p,*r,*s; /********error********/ s=NuLL; while(*str) { p=str; r=t; while(*r) /*******error*********/ if(r==p) { r++; p++; } else { break; } if(*r=='\0') s=str; str++; } return s; } main() { char str[100],t[100],*p; printf("\nplease enter string s:"); scanf("%s",str); printf("\nplease enter substring t:"); scanf("%s",t); p=fun(str,t); if(p) printf("\nthe result is:%s\n",p); else printf("\nnot found!\n"); } 三、編程題 編寫函數(shù)int fun(int mm,int b[MAX]),該函數(shù)的功能是求出小于或等于mm的所有素?cái)?shù),并放在b數(shù)組中,該函數(shù)返回所求出的素?cái)?shù)的個(gè)數(shù)。 請(qǐng)勿改動(dòng)主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號(hào)中填入所編寫的若干語句。 注意:部分源程序給出如下。 # include # include # define MAX 100 int fun(int mm,int b[MAX]) { } main() { int m,i,sum; int b[MAX] ; FILE *out; printf("input a data:\n"); scanf(" %d",&m); sum=fun(m,b); for(i=0 ;i if(i==0 && i!=0) printf("\n"); printf("]",b[i]); } sum=fun(28,b); out=fopen("outfile.dat","w"); for(i=0 ;i fclose(out); } |