2022計算機等級考試二級C題庫及答案_第1頁
2022計算機等級考試二級C題庫及答案_第2頁
2022計算機等級考試二級C題庫及答案_第3頁
2022計算機等級考試二級C題庫及答案_第4頁
2022計算機等級考試二級C題庫及答案_第5頁
已閱讀5頁,還剩252頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、第三分冊 上機考試題庫PAGE PAGE 257計算機等級考試二級C題庫一、填空題給定程序的功能是求1/4的圓周長。函數(shù)通過形參得到圓的直徑,函數(shù)返回1/4的圓周長(圓周長公式為:L=d,在程序中定義的變量名要與公式的變量相同)。例如:輸入圓的直徑值:19.527,輸出為:15.336457請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在橫線上填寫所需的若干表達式或語句。#includedouble fun(double d) return 3.14159*d/4.0;main() double z; printf(Input the d of the round:); scanf(%lf,

2、&z); printf(L=%lfn,fun(z);二、改錯題下列給定程序中函數(shù)fun的功能是:計算正整數(shù)m的各位上的數(shù)字之積。例如,若輸入202,則輸出應(yīng)該是0。請修改程序中的錯誤,得出正確的結(jié)果注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)#include#includelong fun(long n) long r=1; do r*=n%10;n/=10; while(n); return(r);main() long m; printf(nplease enter a number:); scanf(%ld,&m); printf(n%ldn,fun(m);三、編程題

3、請編寫一個函數(shù)fun,它的功能是:求出1到m之內(nèi)(含m)能被7或11整初的所有整數(shù)放在數(shù)組b中,通過n返回這些數(shù)的個數(shù)。例如,若傳送給m的值為20,則程序輸出7 11 14。請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。#include#include#define N 100void fun(int m,int*b,int*n) int i,j=0;*n=0; for(i=1;i=m;i+)if(i%7=0|i%11=0) bj=i; j+; *n=j;main() int aN,n,i; FILE*out; fun(20,a,&n); for(

4、i=0;in;i+)if(i+1)%20=0) printf(%4dn,ai);else printf(%4d,ai); printf(n); out=fopen(outfile.dat,w); fun(100,a,&n); for(i=0;in;i+) if(i+1)%10=0) fprintf(out,%4dn,ai);else fprintf(out,%4d,ai); fclose(out);第2套一、填空題函數(shù)fun的功能是:統(tǒng)計長整數(shù)test的各位上出現(xiàn)數(shù)字5、6、7的次數(shù),并通過外部(全局)變量sum5、sum6、sum7返回主函數(shù)。例如:當(dāng)test=89431676時,結(jié)果應(yīng)該為

5、:sum5=0 sum6=2 sum7=1。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。#includeint sum5,sum6,sum7;void fun(long test) sum5=sum6=sum7=0; while(test) switch(test%10)case 5:sum5+;break;case 6:sum6+;break;case 7:sum7+;test/=10; main() long test=89431676L; fun(test); printf(nThe count result:n); printf(te

6、st=%ld sum5=%d sum6=%d sum7=%dn,test,sum5,sum6,sum7);二、改錯題下列給定程序中,函數(shù)fun的功能是:將字符串str中的小寫字母都改為對應(yīng)的大寫字母,其它字符不變。例如,若輸入“asAS”,則輸出“ASAS”。請修改程序中的錯誤,使它能統(tǒng)計出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)#include#include#includechar*fun(char str) int i; for(i=0;stri;i+) if(stri=a&stri=z) stri-=32; return(str);main() ch

7、ar str81; printf(nplease enter a string:); gets(str); printf(nThe result string is:n%s,fun(str);三、編程題請編寫一個函數(shù)fun,它的功能是:找出一維整型數(shù)組元素中最小的值和它所在的下標(biāo),最小的值和它所在的下標(biāo)通過形參傳回。數(shù)組元素中的值已在主函數(shù)中賦予。主函數(shù)中a是數(shù)組名,n是a中的數(shù)據(jù)個數(shù),min存放最小值,flag存放最小值所在元素的下標(biāo)請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。#include#include#includevoid fun(i

8、nt b,int n,int*min,int*d) int i; *min=b0; *d=0; for(i=0;in;i+) if(bi*min) *min=bi; *d=i; main() int i,a20,min,flag,n=10; FILE*out; for(i=0;in;i+) ai=rand()%50;printf(%4d,ai); printf(n); fun(a,n,&min,&flag); printf(min=%5d,Index=%4dn,min,flag); out=fopen(outflie.dat,w); memcpy(a,3.1415926535897932384

9、62643383279,32); fun(a,8,&min,&flag); fprintf(out,min=%5d,Index=%4d,min,flag); fclose(out);第3套 上機考試試題一、填空題請補充main函數(shù),該函數(shù)的功能是:從鍵盤輸入一組整數(shù),使用條件表達式找出最大的整數(shù)。當(dāng)輸入的整數(shù)為-1時結(jié)束。例如:輸入96 121 23 343 232 54 89 365 89 -1時,最大的數(shù)為365。僅在橫線上填寫所需的若干表達式或語句,請勿改動函數(shù)中的其它任何內(nèi)容#include#include#define NUM 100main() int nNUM; int i=-1

10、; int MAX=-1; printf(nInsert integer with the -1 as end:n); do i+;printf(n%d=,i);scanf(%d,&ni);MAX=MAXni?ni:MAX; while(ni!=-1); printf(The MAX=%dn,MAX);二、改錯題下列給定程序中,函數(shù)fun的功能是:將一個由八進制數(shù)字字符組成的字符串轉(zhuǎn)換為與其數(shù)值相等的十進制整數(shù)。例如,若輸入11111,則輸出將是4681。請修改程序中的錯誤,使它能得出正確結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)#include#include#i

11、ncludeint fun(char*s) int n; n=*s-0; s+; while(*s!=0) n=n*8+*s-0;s+; return n;main() char str6; int i; int n; printf(Enter a string(octal digits):); gets(str); if(strlen(str)5) printf(Error:string too longer!nn);exit(0); for(i=0;stri;i+) if(stri7) printf(Error:%c not is octal digits!nn,stri); exit(0

12、); printf(The original string:); puts(str); n=fun(str); printf(n%s is convered to intege number:%dnn,str,n);三、編程題下列程序定義了NN的二維數(shù)組,并在主函數(shù)中賦值。請編寫函數(shù)fun,函數(shù)的功能是:求出數(shù)組周邊元素的平均值并作為函數(shù)值返回給主函數(shù)中的r。例如:若c數(shù)組中的值為:C=197452383則返回主程序后r的值應(yīng)為4.625000請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句#include#include#include#define

13、 N 3double fun(int bN) int i,j,k=0; double r=0.0; for(j=0;jN;j+) r+=b0j;k+; for(j=0;jN;j+) r+=bN-1j;k+; for(i=1;i=N-2;i+) r+=bi0;k+; for(i=1;i=N-2;i+) r+=biN-1;k+; return r/=k;main() int cNN=1,9,7,4,5,2,3,8,3; int i,j; FILE*out; double r; printf(*n); for(i=0;iN;i+) for(j=0;jN;j+) printf(%4d,cij);pri

14、ntf(n); r=fun(c); printf(THE RESULTn); printf(The r is %lfn,r); out=fopen(outfile.dat,w); fprintf(out,%lf,r); fclose(out);第4套 上機考試試題一、填空題請補充fun函數(shù),該函數(shù)的功能是將字符串str中的小寫字母都改為對應(yīng)的大寫字母,其它字符不變。例如:若輸入”Welcome!”,程序輸出結(jié)果是”WELCOME!”。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。#include#include#includechar*fun(

15、char str) int j; for(j=0;strj;j+) if(strj=a)&(strj=z)strj-=32; return(str);main() char str100; printf(nplease enter a string:); gets(str); printf(nThe result string is:n%s,fun(str);二、改錯題下列給定程序中,函數(shù)fun的功能是:計算并輸出n以內(nèi)最大的10個能被11或19整除的自然數(shù)之和。n的值由主函數(shù)傳入,若n的值為300,則函數(shù)值為2646。請修改程序中的錯誤或在橫線處填上適當(dāng)?shù)膬?nèi)容并把橫線刪除,使程序能得出正確的

16、結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#includeint fun(int n) int m=0,mix=0; while(n=2)&(mix10) if(n%11=0)|(n%19)=0) m=m+n; mix+;n-; return m;main() printf(%dn,fun(300);三、編程題請編寫函數(shù)fun,其功能是:將str所指字符串中除了下標(biāo)為偶數(shù)、同時ASCII值也為偶數(shù)的字符外,其余的全部刪除;串中剩余字符所形成的一個新串放在s所指的數(shù)組中。例如,若str所指字符串中的內(nèi)容為ABCDEFG123456,其中字符A的ASC

17、II碼值為奇數(shù),因此應(yīng)當(dāng)刪除;其中字符B的ASCII值為偶數(shù),但在數(shù)組中的下標(biāo)為奇數(shù),因此也應(yīng)當(dāng)刪除;而字符2的ASCII碼值為偶數(shù),所在數(shù)組中的下標(biāo)也為偶數(shù),因此不應(yīng)當(dāng)刪除,其它以此類推。最后s所指的數(shù)組中的內(nèi)容應(yīng)是246。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#include#includevoid fun(char*str,char s) int i,j=0,n; n=strlen(str); for(i=0;in;i+) if(i%2=0&stri%2=0) sj=stri; j+; sj=

18、0;main() char str100,s100; FILE*out; printf(nplease enter string:); scanf(%s,str); fun(str,s); printf(nThe result is:%sn,s); out=fopen(outfile.dat,w); strcpy(str,please enter string:); fun(str,s); fprintf(out,%s,s); fclose(out);第5套 上機考試試題一、填空題請補充fun函數(shù),該函數(shù)的功能是:依次取出字符串中所有大寫字母,形成新的字符串,并取代原字符串。例如,輸入sdfA

19、SDsd,則輸出ASD。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#includevoid fun(char*s) int j=0; char*p=s; while(*p) if(*p=A&*p=Z) sj=*p; j+;p+; sj=0;main() char str100; printf(nPlease Input a string:); gets(str); printf(nnThe original string is:%sn,str); fun(str); printf(nnThe str

20、ing of changing is:%sn,str);二、改錯題下列給定程序中,函數(shù)fun的功能是:先從鍵盤上輸入一個3行3列矩陣的各個元素的值,然后輸出主對角線元素之和。請修改函數(shù)fun中的錯誤或在橫線處填上適當(dāng)?shù)膬?nèi)容并把橫線刪除,得出正確結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#includevoid fun() int aa33,sum; int i,j; sum=0; for(i=0;i3;i+) for(j=0;j3;j+) scanf(%d,&aaij); for(i=0;i3;i+)sum=sum+aaii; printf(sum=%dn,sum

21、);main() fun();三、編程題請編寫一個函數(shù)void fun(int*s,int t,int*result),用來求出數(shù)組的最小元素在數(shù)組中的下標(biāo),并存放在result所指的存儲單元中。例如,輸入如下整數(shù):564,165,567,121,948,324,329,454,5345,783,434,124,561,985,555則輸出結(jié)果為:3,121。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#includevoid fun(int*s,int t,int*result) int temp,mi

22、n; min=s0; for(temp=0;tempt;temp+) if(stempmin) min=stemp; *result=temp; main() int store15=564,165,567,121,948,324,329,454,5345,783,434,124,561,985,555,result; FILE*out; fun(store,10,&result); printf(%d,%dn,result,storeresult); out=fopen(outfile.dat,w); fprintf(out,%dn%d,result,storeresult); fclose

23、(out);第6套 上機考試試題一、填空題給定程序的功能是判斷字符串s中的某個字符是否與字符ch相同,若相同什么也不做,若不同則插在字符串的最后。例如,輸入test,如果輸入e,輸出的結(jié)果不變,但如果輸入a,結(jié)果testa。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#includevoid fun(char*s,char ch) while(*s&*s!=ch) s+; if(*s!=ch) s0=ch;s1=0; main() char str81,c; printf(nPlease input a stri

24、ng:n); gets(str); printf(n Please enter the character to search:); c=getchar(); fun(str,c); printf(nThe result is %sn,str);二、改錯題下列給定程序中,函數(shù)fun的功能是:按順序給t所指數(shù)組中的元素賦予從2開始的偶數(shù)。然后再按順序?qū)γ?個元素求一個平均值,并將這些值依次存放在r所指的數(shù)組中。若t所指數(shù)組中元素的個數(shù)不是5的倍數(shù),多余部分忽略不計。例如,t所指數(shù)組有14個元素,則只對前10個元素進行處理,不對最后的4個元素求平均值。請修改程序中的錯誤,得出正確的結(jié)果。注意:不要

25、改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#define NUM 20int fun(double*t,double*r) int j,i; double sum; for(j=2,i=0;iNUM;i+) ti=j;j+=2; sum=0.0; for(j=0,i=0;iNUM;i+) sum+=ti;if(i+1)%5=0) rj=sum/5; sum=0; j+; return j;main() double aNUM,bNUM/5; int i,j; j=fun(a,b); printf(The original data:n); for(i=0;iNUM

26、;i+) if(i%5=0)printf(n);printf(%4.0f,ai); printf(nnThe result:n); for(i=0;ij;i+) printf(%6.2f,bi); printf(nn);三、編程題請編寫一個函數(shù)void fun(int x,int sum,int select),該函數(shù)的功能是:將大于整數(shù)x且緊靠x的sum個素數(shù)存入select所指的數(shù)組中。例如,輸入:121 8,則應(yīng)輸出:127 131 137 139 149 151 157 163。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序

27、給出如下。#include#includevoid fun(int x,int sum,int select) int r=0,temp,p,sign=1; for(temp=x+1;tempx*x;temp+) for(p=2;p=temp) if(sum=0) selectr+=temp;sum-; else break; main() int x,y,a500; FILE*out; printf(nInput two number:); scanf(%d,%d,&x,&y); fun(x,y,a); for(x=0;xy;x+) printf(%d ,ax); printf(n); fu

28、n(121,10,a); out=fopen(outfile.dat,w); for(x=0;x10;x+) fprintf(out,%dn,ax); fclose(out);第7套 上機考試試題一、填空題給定程序的功能是計算score中n個人的平均成績aver,將高于aver的成績放在high中,通過函數(shù)名返回人數(shù)。例如,score=88,75,50,60,80,90,n=6時,函數(shù)返回的人數(shù)應(yīng)該是4,high=88,75,80,90。請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#includeint fun(

29、int score,int m,int high) int i,j=0; float aver=0.0; for(i=0;im;i+) aver+=scorei; aver/=(float)m; for(i=0;iaver) highj+=_; return j;main() int i,n,high6; int score6=88,75,50,60,80,90; n=fun(score,6,_); printf(nThe high of average score are:); for(i=0;in;i+) printf(%d ,_); printf(n);二、改錯題已知一個數(shù)列從第0項開始

30、的前三項分別為0、0、1,以后的各項都是其相鄰的前三項之和。下列給定程序中,函數(shù)fun的功能是:計算并輸出該數(shù)列前n項的平方根之和sum。n的值通過形參傳入。例如,當(dāng)n=4時,程序輸出結(jié)果應(yīng)為2.000000。請修改程序中的錯誤,使程序能得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#include#includedouble fun(int n) double sum,a0,a1,a2,a; int i; sum=1.0; if(n=2) sum=0.0; a0=0.0; a1=0.0; a2=1.0; for(i=4;i=n;i+) a=

31、a0+a1+a2;sum+=sqrt(a);a0=a1;a1=a2;a2=a; return sum;main() int n; printf(Input N=); scanf(%d,&n); printf(%lfn,fun(n);三、編程題學(xué)生的記錄由學(xué)號和成績組成,M名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組score中,請編寫函數(shù)fun,它的功能是把分?jǐn)?shù)最低的學(xué)生數(shù)據(jù)放在low所指的數(shù)組中,注意:分?jǐn)?shù)最低的學(xué)生可能不只一個,函數(shù)返回分?jǐn)?shù)最低的學(xué)生的人數(shù)。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#de

32、fine M 10typedef struct char num10; int s;SCORE;int fun(SCORE*a,SCORE*b) int i,j=0,n=0,min; min=a0.s; for(i=0;iM;i+) if(ai.smin) min=ai.s; for(i=0;iM;i+) if(ai.s=min) *(b+j)=ai;j+;n+; return n;main() SCORE stuM=GA03,76,GA04,85,GA01,91,GA08,64,GA06,87,GA014,91,GA011,77,GA017,64,GA018,64,GA016,72; SCO

33、RE lowM; int i,n; FILE*out; n=fun(stu,low); printf(The %d lowest score:n,n); for(i=0;in;i+) printf(%s %4dn,lowi.num,lowi.s); printf(n); out=fopen(outfile.dat,w); fprintf(out,%dn,n); for(i=0;in;i+) fprintf(out,%4dn,lowi.s); fclose(out);第8套 上機考試試題一、填空題請補充main函數(shù),該函數(shù)的功能是:從鍵盤輸入3個整數(shù),然后找出最小的數(shù)并輸出。例如:輸入78,53

34、,123,則輸出為53。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#includemain() int x,y,z,min; printf(nInput three number:n); scanf(%d,%d,%d,&x,&y,&z); printf(The three numbers are:%d,%d,%dn,x,y,z); if(xz) min=z; printf(min=%dn,min);二、改錯題下列給定程序中,fun函數(shù)的功能是:分別統(tǒng)計字符串中小寫字母和大寫字母的個數(shù)。例如,給字符串t輸入:ad

35、fsFFssefSCGSDew,則應(yīng)輸出結(jié)果:big=7,small=10。請修改程序中的錯誤,使它能計算出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#includevoid fun(char*t,int*c,int*d) while(*t) if(*t=A&*t=a&*t=z)(*d)+;t+; main() char t200; int big=0,small=0; printf(nplease input a string:); gets(t); fun(t,&big,&small); printf(n big=%d small=%dn

36、,big,small);三、編程題請編一個函數(shù)void fun(int aMN,int bN),c指向一個M行N列的二維數(shù)組,求出二維數(shù)組每列中最大元素,并依次放入b所指一維數(shù)組中。二維數(shù)組中的數(shù)己在主函數(shù)中賦予。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#include#define M 3#define N 4void fun(int aMN,int bN) int i,j,max; for(j=0;jN;j+) max=a0j;for(i=0;imax) max=aij;bj=max; main(

37、) int cMN=10,22,15,30,19,33,45,38,20,22,66,40; int pN,i,j,k; FILE*out; printf(The original data is:n); for(i=0;iM;i+) for(j=0;jN;j+)printf(%6d,cij); printf(n); fun(c,p); printf(nThe result is:n); for(k=0;kN;k+) printf(%4d,pk); printf(n); out=fopen(outfile.dat,w); for(k=0;kN;k+) fprintf(out,%dn,pk);

38、fclose(out);第9套 上機考試試題一、填空題請補充fun函數(shù),該函數(shù)的功能是:從鍵盤輸入一個下標(biāo)n,把數(shù)組a中比元素an小的元素放在它的左邊,比它大的元素放在它的右邊,排列成的新數(shù)組仍然保存在原數(shù)組中。例如,數(shù)組a=33,55,66,44,77,22,88,99,11,10,輸入2,則 結(jié)果輸出 “33 55 44 22 11 10 66 77 88 99”。請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#define N 10void fun(int a,int n) int i,j=0,k

39、=0,t; int bN; t=an; for(i=0;it) bj+=ai;if(ait) ak+=ai; _; for(i=0;_i+,k+) ak=bi;main() int i,n; int aN=33,55,66,44,77,22,88,99,11,10; printf(The original array:n); for(i=0;iN;i+) printf(%4d,ai); printf(n suffix n:); scanf(%d,&n); fun(a,n); printf(The new array:n); for(i=0;iN;i+) printf(%4d,ai); prin

40、tf(n);二、改錯題下列給定程序中,fun函數(shù)的功能是:求a=xxxx-xx-xx-x(此處xxxx表示n個x,x和n的值在1至9之間)。例如x=3,a=6,則以上表達式為:a=333333-33333-3333-333-33-3其值是296298。X和n是fun函數(shù)的形參,表達式的值作為函數(shù)值傳回main函數(shù)。請修改程序的錯誤,使它能計算出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#includelong fun(int x,int n) int j; long a=0,t=1; for(j=0;j=n;j+) t=t*10+x; a=t

41、; for(j=1;jn;j+) t=t%10;a=a-t; return(a);main() int x,n; printf(nPlease enter x and n:); scanf(%d%d,&x,&n); printf(The value of fun is %ldn,fun(x,n);三、編程題請編寫函數(shù)fun,其功能是:計算并輸出:F=1+(1+)+(1+)+(1+)例如,若主函數(shù)從鍵盤給m輸入10后,則輸出為F=104.478749。請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:m的值要求大于1但不大于100。部分源程序給出如

42、下。#include#includedouble fun(int m) main() int m; double f; FILE*out; printf(nInput m: ); scanf(%d,&m); f=fun(m); printf(nnf=%fnn,f); out=fopen(outfile.dat,w); for(m=0;m10;m+) fprintf(out,%fn,fun(m+20); fclose(out);差第10套*#include#includevoid fun(long a,long*b) int d; long s=1; *b=0; while(a0) d=a%10

43、;if(d%2!=0) *b=d*s+*b; s*=10;a/=10; main() long a,b; printf(nPlease enter a:); scanf(%ld,&a); fun(a,&b); printf(The result is:%ldn,b);第11套 上機考試試題一、填空題請在函數(shù)fun橫線上填寫表達式,使從鍵盤上輸入一個整數(shù)m,輸出 斐波納契數(shù)列。斐波納契數(shù)列是一種整數(shù)數(shù)列,其中每個數(shù)等于前面兩個數(shù)之和,例如:0 1 1 2 3 5 8請勿改動主函數(shù)main與其他函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句#includeint fun(int

44、 m);main() int i,m=0; scanf(%d,&m); for(i=0;im;i+) printf(%d,fun(i);int fun(int m) if(m=0) return 0; else if(m=1) return 1; else return fun(m-1)+fun(m-2);二、改錯題下列給定程序中,函數(shù)fun的功能是:通過某種方式實現(xiàn)兩個變量值的交換,規(guī)定不允許增加語句或表達式.例如變量x中的值原為1,y中的值原為2,程序運行后x中的值為2,y中的值為1。請修改程序中的錯誤,得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#i

45、nclude#includeint fun(int*a,int b) int temp; temp=*a;*a=b; return temp;main() int x=1,y=2; printf(x,y %d %dn,x,y); y=fun(&x,y); printf(the result is %d %dn,x,y);三、編程題請編寫一個函數(shù)void fun(char*t,int p),統(tǒng)計在t字符串中“a”到“z”26個字母各自出現(xiàn)的次數(shù),并依次放在p所指數(shù)組中。例如,當(dāng)輸入字符串sdfssdrefggrthdg后,程序的輸出結(jié)果應(yīng)該是:00031231000000000231000000

46、請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#includevoid fun(char*t,int p) int j; for(j=0;j26;j+) pj=0; while(*t) switch(*t) case a:p0+; break; case b:p1+; break; case c:p2+; break; case d:p3+; break; case e:p4+; break; case f:p5+; break; case g:p6+; break; case h:p7+; break;

47、case i:p8+; break; case j:p9+; break; case k:p10+;break; case l:p11+;break; case m:p12+;break; case n:p13+;break; case o:p14+;break; case p:p15+;break; case q:p16+;break; case r:p17+;break; case s:p18+;break; case t:p19+;break; case u:p20+;break; case v:p21+;break; case w:p22+;break; case x:p23+;bre

48、ak; case y:p24+;break; case z:p25+;break;t+; main() char a2000; int b26,i; FILE*out; printf(nPlease input a char string:); scanf(%s,a); fun(a,b); for(i=0;i26;i+) printf(%d,bi); printf(n); fun(a bosom friend after brings a distant land near,b); out=fopen(outfile.dat,w); for(i=0;i26;i+) fprintf(out,%d

49、n,bi); fclose(out);第12套 上機考試試題一、填空題請補充函數(shù),該函數(shù)的功能是求一維數(shù)組aN的平均值,并對所得結(jié)果進行四舍五入保留兩位小數(shù).例如,當(dāng)a10= 23.1,12.3,5.3,56.4,10.0,13.7,24.5,42,1.2,9.9時,輸出結(jié)果為:average=19.840000.請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。#include#includedouble fun(double a10) int i; long temp; double average=0.0; double sum=0.0; f

50、or(i=0;i10;i+) sum+=ai; average=sum/10; average=average*1000; temp=(average+5)/10; average=(double)temp/100; return average;main() double average,a10=23.1,12.3,5.3,56.4,10.0,13.7,24.5,42,1.2,9.9; int i; printf(nThe data:n); for(i=0;i10;i+) printf(%6.1f,ai); printf(nn); average=fun(a); printf(The ave

51、rage=%fnn,average);二、改錯題下列給定程序中fun函數(shù)的功能是:將n個無序整數(shù)從小到大排列。請修改程序中的錯誤,得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#include#includefun(int n,int*b) int i,j,p,t; for(j=0;jn-1;j+) p=j;for(i=j+1;ibi) p=i; if(p!=j) t=bj; bj=bp; bp=t; putarr(int n,int*z) int i; for(i=1;i=n;i+,z+) printf(%4d,*z);if(!(i%10)

52、printf(n); printf(n);main() int a10=0,4,2,8,6,n=5; printf(nnBefore sorting %d numbers:n,n); putarr(n,a); fun(n,a); printf(nAfter sorting %d numbers:n,n); putarr(n,a);三、編程題編寫函數(shù)fun,函數(shù)的功能是:根據(jù)以下公式計算,計算結(jié)果作為函數(shù)值返回。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。注意:部分源程序給出如下。#include#include#includefloat fun(

53、int n) int k; float str=1.0,sum=1.0; for(k=2;k=n;k+) sum=sum+k;str=str+1/sum; return str;main() int n; float str; FILE*out; printf(nPlease input the integer n:); scanf(%d,&n); str=fun(n); printf(The result is:%fn,str); str=fun(10); out=fopen(outfile.dat,w); fprintf(out,%f,str); fclose(out);第13套 上機考試

54、試題一、填空題請補充fun函數(shù),該函數(shù)的功能是:分類統(tǒng)計一個字符串中元音字母和其它字符的個數(shù)(不區(qū)分大小寫)。例如,輸入UdsaeyiEosu,結(jié)果為A:1 E:2 I:1 O:1 U:2 other:4。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#include#define N 100void fun(char*s,int a) char*r=s; int i=0; for(i=0;i6;i+) ai=0; while(*r) switch(*r) case A: case a:a0+;brea

55、k; case E: case e:a1+;break; case I: case i:a2+;break; case 0: case o:a3+;break; case U: case u:a4+;break; default: a5+; r+; main() char sN,yy5=AEIOU; int i; int a6; printf(Please input a sing to count:n); gets(s); printf(The sing is:n); puts(s); fun(s,a); for(i=0;i5;i+) printf(n%c:%d,yyi,ai); print

56、f(nother:%dn,ai);二、改錯題假定整數(shù)不重復(fù)數(shù)列99,2,6,1,3,4,-1中的數(shù)存放在整數(shù)s中。下列給定程序中,函數(shù)fun的功能是:刪除數(shù)列中值為a的元素,同時將其它元素前移。sum中存放的是數(shù)列中元素的個數(shù)。請修改程序中的錯誤,得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不能更改程序的結(jié)構(gòu)。#include#define M 100fun(int*x,int sum,int a) int temp=0,j; xsum=a; while(a!=xtemp) temp=temp+1; if(temp=sum) return-1; else for(j=temp

57、;jsum;j+)xj=xj+1;return sum-1; main() int sM=99,2,6,1,3,4,-1,a,sum,j; sum=8; printf(The array:n); for(j=0;jsum;j+) printf(%5d,sj); printf(nPlease insert data want to deleted:); scanf(%d,&a); printf(Delete:%dn,a); sum=fun(s,sum,a); if(sum=-1) printf(*Not be found!*nn); else printf(The array after del

58、ete:n);for(j=0;jsum;j+)printf(%5d,sj);printf(nn); 三、編程題請編寫一個函數(shù)void fun(char orig,char result,int flg),其功能是:刪除一個字符串中指定下標(biāo)的字符。其中,orig指向原字符串,刪除后的字符串存放在result所指的數(shù)組中,flg中存放指定的下標(biāo)。例如:輸入一個字符串:Hello World, 然后輸入4,則調(diào)用該函數(shù)后的結(jié)果為:Hell World。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun的花括號中填入所編寫的若干語句。#include#include#define NUM 1

59、00void fun(char orig,char result,int flg) int n,m=0; for(n=0;nNUM;n+) if(n!=flg) resultm=orign;m+; resultm=0;main() char s1NUM,s2NUM; int flg; FILE*out; printf(Please Input s1:n); gets(s1); printf(Input want to delectd:); scanf(%d,&flg); fun(s1,s2,flg); printf(The result is:%sn,s2); fun(test String,

60、s2,9); out=fopen(outfile.dat,w); fprintf(out,%s,s2); fclose(out);第14套 上機考試試題一、填空題s是全部由小寫字母字符和空格字符組成的字符串,由len傳入字符串的長度,請補充fun函數(shù),該函數(shù)的功能是:統(tǒng)計字符串s中的單詞數(shù),結(jié)果由變量len傳回。每個單詞之間都由空格隔開,并且字符串s開始不存在空格。例如,s=“welcome welcome”,結(jié)果為:len=2。請勿改動主函數(shù)main與其它函數(shù)中的任何內(nèi)容,僅在fun函數(shù)的橫線上填寫所需的若干表達式或語句。注意:部分源程序給出如下。#include#define M 100v

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論