




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、1.填空給定程序的功能是調(diào)用fun 函數(shù)建立班級通訊錄。 通訊錄中記錄每位學生的編號,姓名和電話號碼。 班級的人數(shù)和學生的信息從鍵盤讀入,每個人的信息作為一個數(shù)據(jù)塊寫到名為myfile5.dat的二進制文件中。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,是程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的blank1.c 中不得增行或刪行,也不得更改程序的結(jié)構(gòu)!void check(); /*found*/ int fun(_1_ *std) /*found*/ _2_ *fp; int i; if(fp=fopen(myfile5.dat,wb)=null) return(0); pr
2、intf(noutput data to file !n); for(i=0; in; i+) /*found*/ fwrite(&stdi, sizeof(stype), 1, _3_); fclose(fp); return (1); 修改給定程序 modi1.c 中函數(shù) fun 的功能是:先將在字符串s 中的字符按正序存放到 t 串中,然后把 s中的字符按逆序連接到t 串后面。例如:當 s 中的字符串為:“abcde”時,則他中的字符串應為: “abcdeedcba ” 。請改正程序中的錯誤,使他能得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不得更改程序的結(jié)構(gòu)!
3、void fun (char *s, char *t) int i, sl; sl = strlen(s); /*found*/ for( i=0; i=s1; i +) ti = si; for (i=0; isl; i+) tsl+i = ssl-i-1; /*found*/ tsl = 0; 程序函數(shù) fun 的功能是:將兩個兩位數(shù)的正整數(shù)a,b 合并成一個整數(shù)放在c 中。合并的方式是:將 a 數(shù)的十位和個位數(shù)依次放在c 數(shù)的千位和十位上, b 數(shù)的十位和個位數(shù)依次放在c 數(shù)的百位和個位上。例如: a=45,b=12 時,調(diào)用該函數(shù)后, c=4152. 注意:部分源程序存在文件prog1
4、.c中。數(shù)據(jù)文件 in.dat 中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun 的花括號中填入你編寫的若干語句。答案: b: stype file fp m: for(i = 0 ; i sl ; i+) t2*sl = 0; p: *c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10); 2.填空給定程序的功能是:從鍵盤輸入若干行文本(每行不超過80 個字符) ,寫到文件 myfile4.txt 中,用 -1 作為字符串輸入結(jié)束的標記。然后將文件的內(nèi)容讀出顯示在屏幕上。文件的讀寫分別有自定義函數(shù)readtext 和 writete
5、xt實現(xiàn)。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,是程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的blank1.c 中不得增行或刪行,也不得更改程序的結(jié)構(gòu)!main() file *fp; if(fp=fopen(myfile4.txt,w)=null) printf( open fail!n); exit(0); writetext(fp); fclose(fp); if(fp=fopen(myfile4.txt,r)=null) printf( open fail!n); exit(0); readtext(fp); fclose(fp); /*found*/ void wr
6、itetext(file _1_) char str81; printf(nenter string with -1 to end :n); gets(str); while(strcmp(str,-1)!=0) /*found*/ fputs(_2_,fw); fputs(n,fw); gets(str); void readtext(file *fr) char str81; printf(nread file and output to screen :n); fgets(str,81,fr); while( !feof(fr) ) /*found*/ printf(%s,_3_); f
7、gets(str,81,fr); 修改給定程序 modi1.c 中函數(shù) fun 的功能是:從低位開始取出長整形變量s中的奇數(shù)位上的數(shù),依次構(gòu)成一個新數(shù)放在t 中,高位仍放在高位,低位仍放在低位。例如:當 s 中的數(shù)為: 7654321時,t 中的數(shù)為: 7531 請改正程序中的錯誤,使他能得出正確的結(jié)果。注意:不要改動main函數(shù),不能增行或刪行,也不得更改程序的結(jié)構(gòu)!#include /*found*/ void fun (long s, long t) long sl=10; *t = s % 10; while ( s 0) s = s/100; *t = s%10 * sl + *t;
8、 /*found*/ sl = sl*100; 程序函數(shù) fun 的功能是:將兩個兩位數(shù)的正整數(shù)a,b 合并成一個整數(shù)放在c 中。合并的方式是:將 a 數(shù)的十位和個位數(shù)依次放在c 數(shù)的千位和十位上, b 數(shù)的十位和個位數(shù)依次放在c 數(shù)的百位和個位上。例如: a=45,b=12 時,調(diào)用該函數(shù)后, c=1524. 注意:部分源程序存在文件prog1.c中。數(shù)據(jù)文件 in.dat 中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun 的花括號中填入你編寫的若干語句。2、b: *fw str str m: long *t sl = sl*10; p: *c=(b/10)*1
9、000+(a%10)*100+(b%10)*10+(a/10); 3.填空給定程序中, 函數(shù) fun 的功能是: 將自然數(shù) 110以及它們的平方根寫到名為 myfile3txt 的文本文檔中,然后再順序讀出顯示在屏幕上。請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除,是程序得出正確的結(jié)果。注意:源程序存放在考生文件夾下的blank1.c 中不得增行或刪行,也不得更改程序的結(jié)構(gòu)!int fun(char *fname ) file *fp; int i,n; float x; if(fp=fopen(fname, w)=null) return 0; for(i=1;i=10;i+) /*fou
10、nd*/ fprintf(_1_,%d %fn,i,sqrt(double)i); printf(nsucceed!!n); /*found*/ _2_; printf(nthe data in file :n); /*found*/ if(fp=fopen(_3_,r)=null) return 0; fscanf(fp,%d%f,&n,&x); while(!feof(fp) printf(%d %fn,n,x); fscanf(fp,%d%f,&n,&x); fclose(fp); return 1; 修改給定程序 modi1.c 中 fun 函數(shù)的功能是
11、:將n個無序整數(shù)從小到大排序。fun ( int n, int *a ) int i, j, p, t; for ( j = 0; jn-1 ; j+ ) p = j; /*found*/ for ( i=j+1; iai ) /*found*/ t=i; if ( p!=j ) t = aj; aj = ap; ap = t; 程序函數(shù) fun 的功能是:將兩個兩位數(shù)的正整數(shù)a,b 合并成一個整數(shù)放在c 中。合并的方式是:將 a 數(shù)的十位和個位數(shù)依次放在c 數(shù)的千位和十位上, b 數(shù)的十位和個位數(shù)依次放在c 數(shù)的百位和個位上。例如: a=45,b=12 時,調(diào)用該函數(shù)后, c=2514 注意
12、:部分源程序存在文件prog1.c中。數(shù)據(jù)文件 in.dat 中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun 的花括號中填入你編寫的若干語句。3、b: fp fclose(fp) fname m: i 0) d = s%10; /*found*/ if (d%2=0) *t=d* sl+ *t; sl *= 10; /*found*/ s = 10; 程序函數(shù) fun 的功能是:將兩個兩位數(shù)的正整數(shù)a,b 合并成一個整數(shù)放在c 中。合并的方式是:將 a 數(shù)的十位和個位數(shù)依次放在c 數(shù)的千位和十位上, b 數(shù)的十位和個位數(shù)依次放在c 數(shù)的百位和個位上。例如: a=
13、45,b=12 時,調(diào)用該函數(shù)后, c=5142 注意:部分源程序存在文件prog1.c中。數(shù)據(jù)文件 in.dat 中的數(shù)據(jù)不得修改。請勿改動主函數(shù)main和其他函數(shù)中的任何內(nèi)容,僅在函數(shù)fun 的花括號中填入你編寫的若干語句。4、b: “ r” fs ft m: (d%2=0) s /= 10; p: *c=(a%10)*1000+(b/10)*100+(a/10)*10+(b%10); 5.填空給定程序中已建立一個帶有頭結(jié)點的單向鏈表,鏈表中的各節(jié)點按結(jié)點數(shù)據(jù)域中的數(shù)據(jù)遞增有序鏈表。 函數(shù) fun 的功能是: 把形參 x 的值放入一個新結(jié)點并插入到鏈表中,插入后結(jié)點數(shù)據(jù)域的值仍保持遞增有序
14、。typedef struct list int data; struct list *next; slist; void fun( slist *h, int x) slist *p, *q, *s; s=(slist *)malloc(sizeof(slist); /*found*/ s-data=_1_; q=h; p=h-next; while(p!=null & xp-data) /*found*/ q=_2_; p=p-next; s-next=p; /*found*/ q-next=_3_; 修改給定程序 modi1.c 中函數(shù) fun 的功能是:計算正整數(shù) num的各位
15、上的數(shù)字之積。例如,若輸入: 252,則輸入應該是: 20.若輸入: 202,則輸出應該是: 0. long fun (long num) /*found*/ long k; do k*=num%10 ; /*found*/ num=10 ; while(num) ; return (k) ; 請編寫一個函數(shù)fun,它的功能是:它的功能是:計算n門課程的平均分,計算結(jié)果作為函數(shù)值返回。例如:若有 5 門課程的成績是: 90.5,72,80,61.5,55 則函數(shù)的值為: 71.80 5、b: x p s m: long k=1; num/=10 ; p: int i; float ave=0.
16、0; for(i=0; inext; s=p; while(t-next != null) s=t; /*found*/ t=t-_1_; /*found*/ printf( %d ,_2_); s-next=null; /*found*/ free(_3_); 修改給定程序 modi1.c 中函數(shù) fun的功能是:將字符串中的字符按逆序輸出,單補改變字符串中的內(nèi)容。例如,若字符串味abcd,則應輸出: dcba /*found*/ fun (char a) if ( *a ) fun(a+1) ; /*found*/ printf(%c *a) ; 程序請編寫一個函數(shù) fun,他的功能是:比
17、較兩個字符串的長度(不得調(diào)用c語言提供的求字符串長度的函數(shù)) ,函數(shù)返回較長的字符串。 若兩個字符串長度相同,則返回第一個字符串。例如,輸入beijingshanghai(為回車鍵 ),函 數(shù)將返回shanghai 6、b: next t-data t m: fun (char *a) printf(%c, *a) ; p: int i; char *p=s, *q=t; for(i=0;*p & *q; i+) p+; q+; if(*p = 0 & *q = 0) return s ; if(*p) return s ; else return t ; 7.填空給定程序中建
18、立一個帶有頭結(jié)點的單向鏈表,鏈表中的各節(jié)點按數(shù)據(jù)域遞增有序連接。函數(shù)fun 的功能是:刪除鏈表中數(shù)據(jù)域值相同的結(jié)點,使之只保留一個typedef struct list int data; struct list *next; slist; void fun( slist *h) slist *p, *q; p=h-next; if (p!=null) q=p-next; while(q!=null) if (p-data=q-data) p-next=q-next; /*found*/ free(_1_); /*found*/ q=p-_2_; else p=q; /*found*/ q=q
19、-_3_; 修改給定程序 modi1.c 中函數(shù) fun 的功能是:用選擇法對數(shù)組中的n 個元素按從小到大的順序進行排序。void fun(int a, int n) int i, j, t, p; for (j = 0 ;j n-1 ;j+) /*found*/ p = j for (i = j;i n; i+) if(ai ap) /*found*/ p = j; t = ap ; ap = aj ; aj = t; 請編寫一個函數(shù)fun,它的功能是:求出1 到 m 之間(含 m)能被 7 或 11整除的所有整數(shù)放在數(shù)組a 中,通過 n 返回這些數(shù)的個數(shù)。 例如,若傳 3 送給 m的之位
20、50,則程序輸出: 7 11 14 21 22 18 33 35 42 44 49 答案:7、b: q next next m: p = j; p=i; p: int i ; *n=0 ; for(i=7 ; inext; /*found*/ while(p!=_1_) n+; /*found*/ if (p-data=ch) return _2_; else p=p-next; return 0; 修改給定程序 modi1.c 中函數(shù) fun 的功能是:刪除 p 所指字符串中的所有空白字符(包括制表符,回車符及換行符)輸入字符串是用“ #”結(jié)束輸入。fun ( char *p) int i,
21、t; char c80; /*found*/ for (i = 0,t = 0; pi ; i+) if(!isspace(*(p+i) ct+=pi; /*found*/ ct=0; strcpy(p,c); 程序請編寫一個函數(shù) fun,它的功能是: 將 ss所指字符串中所有下標為奇數(shù)位置上的字母轉(zhuǎn)換成大寫(若該位置上不是字母,則不轉(zhuǎn)換)例如:若輸入“ abc4efg ” ,則應輸出“ abc4efg” 。答案:8、b: null n head,ch m: for ct=0; p: int i ; for(i = 1 ; i = a & ssi next; while(p) (*n)
22、+; /*found*/ p=p-_2_; main() slist *head; int an=12,87,45,32,91,16,20,48, num; head=creatlist(a); outlist(head); /*found*/ fun(_3_, &num); printf(nnumber=%dn,num); 修改給定程序 modi1.c 中函數(shù) fun 的功能是: 求出 s所指字符串中最后一次出現(xiàn)的 t 所指子字符串的地址,通過函數(shù)返回值返回,在主函數(shù)中輸出從此地址開始的字符串;若未找到,則函數(shù)值為null 例如:當字符串中的內(nèi)容為“abcdefabcdx ”t 中的
23、內(nèi)容為“ ab”時,輸出的結(jié)果應是: abcdx 當字符串中的內(nèi)容為“ abcdefabcdx ”t 中的內(nèi)容為“ abd”時,則程序輸出未找到信息 not be found char * fun (char *s, char *t ) char *p , *r, *a; /*found*/ a = null; while ( *s ) p = s; r = t; while ( *r ) /*found*/ if ( r = p ) r+; p+; else break; if ( *r = 0 ) a = s; s+; return a ; 程序函數(shù) fun 的功能是: 將 s所指字符串中
24、除了下標問為偶數(shù),同時 ascii 值也為偶數(shù)的字符外,其余的全部刪除:串中剩余字符所形成的一個新串放在t 所指的數(shù)組中例如,若 s所指的字符串中的內(nèi)容為 “abcdefg123456” ,其中字符 a 的 ascii碼味奇數(shù),因此應當刪除,其中字符b 的 ascii 碼值為偶數(shù),但是在數(shù)組中的下標為基數(shù),因此也當刪除;答案9、b: *n next head m: a = null; *r = *p p: int i, j = 0 ; for(i = 0 ; i next; while(p) /*found*/ s+= p-_1_; /*found*/ p=p-_2_; return s; 修
25、改給定程序 modi1.c 中函數(shù) fun 的功能是:將 s 所指字符串中出現(xiàn)的與t1 所指字符串相同的字串全部替換成t2 所指字符串,所形成的新串放在w 所指的數(shù)組中,在此處,要求 t1 和 t2 所指字符串的長度相同。int fun (char *s, char *t1, char *t2 , char *w) int i; char *p , *r, *a; strcpy( w, s ); while ( *w ) p = w; r = t1; /*found*/ while ( r ) if ( *r = *p ) r+; p+; else break; if ( *r = 0 ) a
26、 = w; r = t2; while ( *r ) /*found*/ *a = *r; a+; r+ w += strlen(t2) ; else w+; 程序函數(shù) fun 的功能是 ;將 s所指字符串下標為偶數(shù)的字符刪除,串中剩余字符形成的新串放在 t 所指的數(shù)組中例如:當 s 所指字符串中的內(nèi)容為: “abcdefghijk ”在 t 所指數(shù)組中的內(nèi)容應是“bdfhj”10、b: data next head m: *r r+; p: int i, j = 0 ; for(i = 1 ; i strlen(s); i+=2) tj+ = si ; tj = 0 ; 11. 填空人員記錄
27、有編號和出生年月日組成,n 名人員的數(shù)據(jù)已在主函數(shù)中存入結(jié)構(gòu)體數(shù)組 std中,且編號唯一。 函數(shù) fun 的功能是: 找出數(shù)據(jù)中的編號為空串。/*found*/ _1_ fun(stu *std, char *num) int i; stu a=,9999,99,99; for (i=0; in; i+) /*found*/ if( strcmp(_2_,num)=0 ) /*found*/ return (_3_); return a; 修改給定程序 modi1.c 中函數(shù) fun 的功能是:從 s 所指字符串中,找出與t所指字符串相同的字串的個數(shù)作為函數(shù)返回值例如,當 s所指字符串中的內(nèi)容
28、為:“abcdabfab ” , t 所指字符串的內(nèi)容為:“ab”則函數(shù)返回整數(shù)3 int fun (char *s, char *t) int n; char *p , *r; n = 0; while ( *s ) p = s; r = t; while ( *r ) if ( *r = *p ) /*found*/ r+; p+ else break; /*found*/ if ( r = 0 ) n+; s+; return n; 函數(shù) fun 的功能是:將 s 所指字符串中 ascii 值為偶數(shù)的字符刪除,串中剩余字符形成一個新串放在t 所指的數(shù)組中例如,若 s 所指字符串中的內(nèi)容為
29、“ abcdefg12345” ,其中字符 b 的ascii 碼值為偶數(shù) . 答案:11、b: stu stdi.num stdi m: p+; *r= ? 0? ; p: int i, j = 0 ; for(i = 0 ; i strlen(s); i+) if(si % 2) tj+ = si ; tj = 0 ; 12填空人員的記錄由編號和出生年月日組成n 名成員的數(shù)據(jù)已在主函數(shù)中存入結(jié)構(gòu)體數(shù)組 std 中,函數(shù) fun 的功能是:找出指定出生年份的人員,將其數(shù)據(jù)放在形參k 所指的數(shù)組中,由主函數(shù)輸出,同事有函數(shù)值返回滿足指定條件的人數(shù)int fun(stu *std, stu *k,
30、 int year) int i,n=0; for (i=0; in; i+) /*found*/ if( _1_=year) /*found*/ kn+= _2_; /*found*/ return (_3_); 修改給定程序 modi12 。c 的功能是:讀入一個整數(shù)k(2k1000) ,打印她的所有因子例如 2310,則應輸出 2,3,5,7,11 /*found*/ isprime ( int n ); int i, m; m = 1; for ( i = 2; i n; i+ ) /*found*/ if !( n%i ) m = 0; break ; return ( m ); 設
31、計已知學生的記錄有學號成績構(gòu)成,n 名學生的數(shù)據(jù)已經(jīng)存入結(jié)構(gòu)體數(shù)組a中。編寫函數(shù) fun,函數(shù)功能是:找出成績最高的學生記錄,通過形參指針傳回主函數(shù)(規(guī)定只有一個最高分) 。已給出函數(shù)的首部,請完成該函數(shù)12、b: stdi.year stdi n m: 分號去掉if (!( n%i ) p: int i, max = a0.s, j = 0; for(i = 1 ; i n ; i+) if(max ai.s) j = i ; max = ai.s ; *s = aj ; 13填空給定程序通過定義并賦初值的方式,利用結(jié)構(gòu)體變量存儲了一名學生的學號,姓名和 3 們課程的成績,函數(shù)fun 的功能
32、是將該學生的各科成績都乘以一個系數(shù)a void show(stu tt) int i; printf(%d %s : ,tt.num,); for(i=0; i3; i+) printf(%5.1f,tt.scorei); printf(n); /*found*/ void modify(_1_ *ss,float a) int i; for(i=0; i_2_ *=a; main( ) stu std= 1,zhanghua,76.5,78.0,82.0 ; float a; printf(nthe original number and name and scores :n)
33、; show(std); printf(ninput a number : ); scanf(%f,&a); /*found*/ modify(_3_,a); printf(na result of modifying :n); show(std); 修改給定程序 modi 。c 中函數(shù) fun 的功能是:求 k!(k 0 return (k*fun(k-1); /*found*/ else if ( k=0 ) return 1l; 設計程序定義了 n*n 的二維數(shù)組。 并在主函數(shù)中自動賦值, 請編寫函數(shù) fun,函數(shù)的功能是:使數(shù)組左下三角元素的值乘以n 例如:若 n 的值為 3,
34、a 數(shù)組的值為13、b: stu scorei &std m: ( ) k= =0 p: int i, j; for(i = 0 ; i n ; i+) for(j = 0 ; j std1.num) temp=std0; std0=std1; std1=temp; if(std0.numstd2.num) temp=std0; std0=std2; std2=temp; if(std1.numstd2.num) temp=std1; std1=std2; std2=temp; main() person std = 5,zhanghu,2,wangli,6,linmin ; int
35、i; /*found*/ fun(_3_); printf(nthe result is :n); for(i=0; i3; i+) printf(%d,%sn,stdi.num,); 修改給定程序 modi1.c 中函數(shù) fun 的功能是:將 m 個字符串連接起來組成一個新串,放入 pt 所指存儲區(qū)中int fun ( char str10, int m, char *pt ) /*found*/ int k, q, i ; for ( k = 0; k m; k+ ) q = strlen ( str k ); for (i=0; iq; i+) /*found*/ pt
36、i = strk,i ; pt += q ; pt0 = 0 ; 設計程序定義了 n*n 的二維數(shù)組,并在主函數(shù)中自動賦值,請編寫函數(shù)fun,函數(shù)的功能是:使數(shù)組左下三角元素中的值全部值0 14、b: *std person std m: int strki p: int i, j; for(i = 0 ; i n ; i+) for(j = 0 ; j = i; j+) aij =0; 15.填空給定程序中,函數(shù)fun 的功能是:將形參std 所指結(jié)構(gòu)體數(shù)組中年齡最大者的數(shù)據(jù)作為函數(shù)值返回,并在主函數(shù)中輸出std fun(std std, int n) std max; int i; /*f
37、ound*/ max= _1_; for(i=1; in; i+) /*found*/ if(max.age_2_) max=stdi; return max; main( ) std std5=aaa,17,bbb,16,ccc,18,ddd,17,eee,15 ; std max; max=fun(std,5); printf(nthe result: n); /*found*/ printf(nname : %s, age : %dn, _3_,max.age); 修改給定程序 modi1.c 中函數(shù) fun 的功能是:實現(xiàn)兩個整數(shù)的交換例如給 a和 b 分別輸入 60 和 65,輸出為
38、: a=65 b=60 /*found*/ void fun ( int a, b ) int t; /*found*/ t = b; b = a ; a = t; 設計請編制一個函數(shù) fun,tt 指向一個 m 行 n 列的二維數(shù)組, 求二維數(shù)組每列中最小元素,并以此放入pp 所指一維數(shù)組中。二維數(shù)組中的數(shù)已在主函數(shù)中賦予15、b: *std stdi.age m: int *b t = *b; *b = *a ; *a = t; p: int i,j, min, k ; for(i = 0 ; i n ; i+) min = tt0i ; k = 0 ; for(j =
39、1 ; j ttji) min=ttji ; k = j ; ppi = ttki ; 16.填空程序通過定義并賦初值的方式, 利用結(jié)構(gòu)體變量存儲了一名學生的信息,函數(shù) fun的功能是輸出這位學生的信息/*found*/ void show(stu _1_) int i; printf(n%d %s %c %d-%d-%d, tt.num, , tt.sex, tt.birthday.year, tt.birthday.month, tt.birthday.day); for(i=0; i3; i+) /*found*/ printf(%5.1f, _2_); printf(n)
40、; main( ) stu std= 1,zhanghua,m,1961,10,8,76.5,78.0,82.0 ; printf(na student data:n); /*found*/ show(_3_); 修改給定程序 modi1.c 中函數(shù) fun 的功能是:求出數(shù)組中最大數(shù)和次大數(shù),并把最大數(shù)和 a【0】中的數(shù)對調(diào),次最大數(shù)和a【1】中的書對調(diào)int fun ( int * a, int n ) int i, m, t, k ; for(i=0;i2;i+) /*found*/ m=0; for(k=i+1;kam) k=m; t=ai;ai=am;am=t; 設計請編寫一個函數(shù)
41、unsigned fun ,w 是一個大與 10 的無符號整數(shù),若w 是 n 為的整數(shù),函數(shù)求出 w 的低 n-1 位的數(shù)作為函數(shù)值返回例如 w 為 5923 則函數(shù)返回 923;16、b: tt tt.scorei std m: m=i m=k p: if(w10000) w %= 10000 ; else if(w1000) w %= 1000 ; else if(w100) w %= 100 ; else if(w10) w %=10 ; return w ; 17.填空給定程序中,函數(shù)fun 的功能是:對形參ss所指字符串數(shù)組中的m 個字符串按長度由短到長進行排序。ss所指字符串數(shù)組中
42、共有m 個字符串,且串長 n void fun(char (*ss)n) int i, j, k, nm; char tn; for(i=0; im; i+) ni=strlen(ssi); for(i=0; im-1; i+) k=i; /*found*/ for(j=_1_; jnj) _2_; if(k!=i) strcpy(t,ssi); strcpy(ssi,ssk); /*found*/ strcpy(ssk,_3_); nk=ni; 給定程序 modi 。c 中函數(shù) fun 的功能是:判斷ch中字符是否與 str 所指串中的某個字符相同;若相同,什么也不做,若不同,則將其插在串的
43、最后#include /*found*/ void fun(char str, char ch ) while ( *str & *str != ch ) str+; /*found*/ if ( *str = ch ) str 0 = ch; /*found*/ str1 = 0; 設計請編制一個函數(shù) fun,函數(shù)功能是吧s所指字符串中的內(nèi)容逆值17、b: i+1 k=j t m: char *str != 0 p: char bn ; int i = 0, j ; for(j = strlen(s) - 1 ; j = 0 ; j-) bi+ = sj ; bi=0; strcpy
44、(s, b) ; 18.填空給定程序中,函數(shù) fun 的功能是:求出形參 ss所指的字符串數(shù)組中最長字符串的長度,其余字符串左邊用字符*補齊,使其與最長的字符串等長,字符串數(shù)組中共有 m 個字符串void fun(char (*ss)n) int i, j, k=0, n, m, len; for(i=0; in) /*found*/ n=len; _1_=i; for(i=0; i=0; j-) ssim-=ssij; for(j=0; j1 & n170) /*found*/ result*=-n; /*found*/ return _; 設計編寫函數(shù) fun,函數(shù)的功能是:從s
45、所指的字符串中刪除給定字符。同一個字母的大小寫按不同字符處理18、 b: k len ssij m: n- result p: char *p = s ; int i = 0 ; while(*p) if(*p != c) si+ = *p ; p+ ; si = 0 ; 19.填空給定程序中,函數(shù)fun 的功能是:求出形參ss所指字符串數(shù)組中最長字符串的長度,將其余字符串右邊用字符*補齊,使其與最長的字符串等長。ss所指的字符串數(shù)組中共有 m 個字符串void fun(char (*ss)n) int i, j, n, len=0; for(i=0; in)n=len; for(i=0; i
46、m; i+) /*found*/ n=strlen(_1_); for(j=0; jlen-n; j+) /*found*/ ssi _2_=*; /*found*/ ssin+j+ _3_=0; 修改給定程序 modi1 。c 中函數(shù) fun 的功能是將: p 所指字符串中每個單詞的最后一個字母改成大寫#include void fun( char *p ) int k = 0; for( ; *p; p+ ) if( k ) /*found*/ if( p = ) k = 0; /*found*/ * (p-1) = toupper( *( p - 1 ) ) else k = 1; 設計
47、請編寫函數(shù) fun,對長多為 7 個字符的字符串,除首,尾字符外,將其余5 個字符按 ascii 降序排列19、 b: ssi n+j 1 m: *p ; p: char ch ; int i, j ; for(i = 1 ; i 6 ; i+) for(j = i + 1 ; j 6 ; j+) if(*(s + i) *(s + j) ch = *(s + j) ; *(s + j) = *(s +i) ; *(s + i) = ch ; 20.填空給定程序中,函數(shù)fun 的功能是:求 ss所指字符串數(shù)組中長度最長的字符串所在的行下標,作為函數(shù)值返回,并把其串長放在形參n 所指變量中。 s
48、s 所指字符串數(shù)組中共有m 個字符串#define n 20 /*found*/ int fun(char (*ss) _1_, int *n) int i, k=0, len=0; for(i=0; i*n) /*found*/ _3_; k=i; return(k); 修改給定程序 modi1.c 中函數(shù) fun的功能是:根據(jù)形參m,計算如下公式的值double fun( int m ) double t = 1.0; int i; for( i = 2; i = m; i+ ) /*found*/ t += 1.0/k; /*found*/ _ 設計編寫一個函數(shù),該函數(shù)可以統(tǒng)計一個長度為
49、2 的字符串在另個字符串中出現(xiàn)的次數(shù)20、b: n len *n=len m: t += 1.0/i; return t; p: int cnt = 0 ; char *p = str, *q ; while(*p) q = strstr(p, substr) ; if(q = null) break; p = q + strlen(substr) ; cnt+ ; return cnt ; strstr:在前串中找出后串第一次出現(xiàn)的位置,若找到返回地址否則返回null 21.填空給定程序中,函數(shù)fun 的功能是:求 ss所指字符串數(shù)組中長度最短的字符串所在的行下標,作為函數(shù)值返回,并把其串長
50、放在形參n所指變量中int fun(char (*ss)n, int *n) int i, k=0, len= n; /*found*/ for(i=0; i_1_; i+) len=strlen(ssi); if(i=0) *n=len; /*found*/ if(len _2_ *n) *n=len; k=i; /*found*/ return(_3_); 修改給定程序 modi1.c 中函數(shù) fun 的功能是: 將 tt 所指字符串中的小寫字母都改為對應的大寫字母,其他字符不變char* fun( char tt ) int i; for( i = 0; tti; i+ ) /*foun
51、d*/ if( a = tti )|( tti = z ) ) /*found*/ tti += 32; return( tt ); 設計請編寫函數(shù) fun,其功能是:將所有大于1 小于整數(shù) m 的非素數(shù)存入 xx所指數(shù)組中,非素數(shù)的個數(shù)通過k 傳回21、b: m k m: & tti -= 32; p: int i,j;*k=0;for(i=2;im;i+)for(j=2;j=i/2;j+)if(i%j=0) break; if(j=0 & si=9) /*found*/ t2j=si; _1_; else t1k+=si; t2j=0; t1k=0; /*found*/ f
52、or(i=0; ik; i+) _2_; /*found*/ for(i=0; i_3_; i+) sk+i=t2i; 修改給定程序 modi1.c 中函數(shù) fun的功能是:用冒泡法對6 個字符串由小到大的順序進行排序fun ( char *pstr6) int i, j ; char *p ; for (i = 0 ; i 5 ; i+ ) /*found*/ for (j = i + 1, j 0) p = *(pstr + i) ; /*found*/ *(pstr + i) = pstr + j ; *(pstr + j) = p ; 設計請編寫函數(shù) fun,它的功能是:求出ss 所指
53、字符串中指定字符的個數(shù),并返回此值22、b: j+ si=t1i j m: ; ; *(pstr + j) p: int cnt = 0 ; char *p = ss ; while(*p) if(*p = c) cnt+ ; p+ ; 23.填空給定程序中, 函數(shù) fun 的功能是: 在形參所指字符串中的每個數(shù)字字符之后插入一個*號void fun(char *s) int i, j, n; for(i=0; si!=0; i+) /*found*/ if(si=0 _1_ sii; j-) /*found*/ sj+1= _3_; sj+1=*; i=i+1; 修改給定程序 modi1.c
54、 中函數(shù) fun 的功能是;根據(jù)整形形參m,計算如下公式的值設計請編寫函數(shù) fun,函數(shù)功能是: 實現(xiàn) b=a+a ,即把矩陣 a 加上 a 的轉(zhuǎn)職,存放到 b 中23、b: & 0 sj m: = 1.0 p: int c33 ; int i, j ; for(i = 0 ; i 3 ; i+) for(j = 0 ; j =0&si= _2_ ) n+; /*found*/ _3_ ; 修改給定程序 modi1.c 中函數(shù) fun 的功能是:通過某種方式實現(xiàn)倆個變量值的交換,規(guī)定不予許增加語句和表達式int fun(int *x,int y) int t ; /*found
55、*/ t = x ; x = y ; /*found*/ return(y) ; 設計請編寫函數(shù) fun,它的功能是:求出1 到 1000 之間能被 7 或 11 整除,但不能同時被 7 和 11 整除的所有整數(shù)并將他們放在a 所指的數(shù)組中,通過n 返回這些數(shù)的個數(shù)24、b: si ,9?*t=n; m: t = *x ; *x = y ; return(t) ; p: int i ; *n = 0 ; for(i = 7 ; i =1; i=i-2) si+2=si; /*found*/ s1=_3_ ; 給定程序 modi1.c 中 fun 函數(shù)的功能是:求s=aaaa-.aaa-aa-a
56、 long fun (int a, int n) int j ; /*found*/ long s = 0, t = 1 ; for ( j = 0 ; j n ; j+) t = t * 10 + a ; s = t ; for ( j = 1 ; j n ; j+) /*found*/ t = t % 10 ; s = s - t ; return(s) ; 設計請編寫一個函數(shù) fun,統(tǒng)計在 tt 所指字符串中 ? a? 到? z? 26 個小寫字母各自出現(xiàn)的次數(shù),并依次放在pp 所指數(shù)組中25、b: n-1 sk c m: t=0 t=t/10 p: char *p = tt ; in
57、t i ; for(i = 0 ; i = a & *p = z) pp*p - a += 1 ; p+ ; 26.填空給定程序中,函數(shù)fun 的功能是:對形參s 所指字符串中下標為奇數(shù)的字符按 ascii 碼大小遞增排序,并將排序后下標為基數(shù)的字符取出,存入形參p 所指字符數(shù)組中,形成一個新串void fun(char *s, char *p) int i, j, n, x, t; n=0; for(i=0; si!=0; i+) n+; for(i=1; in-2; i=i+2) /*found*/ _1_; /*found*/ for(j=_2_+2 ; jsj) t=j; if
58、(t!=i) x=si; si=st; st=x; for(i=1,j=0; i= num) pi = pi + t ; n = n + 2 ; s = -s ; /*found*/ t = s % n ; pi = pi * 4 ; return pi ; 請編寫一個函數(shù) fun,其功能是:刪除一個字符串中指定下標的字符,其中,a 指向原字符,刪除指定字符后的字符串存在b 所指的數(shù)組中, n 中存放指定下標26、b: t=i; i 0 m: (fabs(t) s/n p: strncpy(b, a, n) ; bn = 0 ; strcat(b, a + n + 1) ; 27 填空給定程序
59、中,函數(shù)fun 的功能是:在形參所指字符串中尋找一個字符串與參數(shù)c相同的字符, 并在其后插入一個與之相同的字符,若找不到相同的字符則函數(shù)不做任何處理void fun(char *s, char c) int i, j, n; /*found*/ for(i=0; si!=_1_ ; i+) if(si=c) /*found*/ n=_2_ ; while(si+1+n!=0) n+; for(j=i+n+1; ji; j-) sj+1=sj; /*found*/ sj+1=_3_ ; i=i+1; 修改在主函數(shù)中從鍵盤輸入若干個數(shù)放入數(shù)組中,用 0 結(jié)束輸入并放在最后一個元素中,給定程序mod
60、i1。c 中函數(shù) fun 的功能是:計算數(shù)組元素中值為正數(shù)的平均值double fun ( int x) /*found*/ int sum = 0.0; int c=0, i=0; while (xi != 0) if (xi 0) sum += xi; c+; i+; /*found*/ sum = c; return sum; 設計編寫函數(shù) fun,函數(shù)功能是:根據(jù)以下公式s,計算結(jié)果作為函數(shù)返回值,n 通過形參傳入27、b: 0 0 c m: double /= p: int i,j,t; float s=0; for(i=1;i=n;i+) t+=j;s=s+1./t; return s; 28.給定程序中, 函數(shù) fun 的功能是 :有 n*n 的矩陣,根據(jù)給定的 m的值,將每行元素中的值均右移m個位置,左邊置為0 #de
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 建筑工程居間合同書
- 婚姻介紹擔保合同
- 小區(qū)物業(yè)管理商鋪服務合同
- 房屋買賣居間服務合同協(xié)議書
- 房屋委托居間出租合同
- 房子裝修維修工程合同
- 消防工程三方合同
- 房屋外墻維修合同協(xié)議書
- 消納合同附加協(xié)議
- 醫(yī)院合同解除協(xié)議
- 2025-2030年中國CAE軟件行業(yè)市場行情監(jiān)測及發(fā)展前景研判報告
- 術(shù)前討論制度課件
- 2025-2030中國工程造價咨詢行業(yè)市場深度調(diào)研及競爭格局與投資研究報告
- 購物卡采購合同
- 國開電大軟件工程形考作業(yè)3參考答案
- 國家開放大學《會計學概論》形考任務1-4參考答案
- 新浙教版七年級上冊初中科學 第2節(jié) 質(zhì)量的測量 教學課件
- 中華人民共和國招標投標法(PPT)
- 統(tǒng)編版四年級道德與法治下冊第8課《這些東西哪里來》精美課件(含視頻)
- 手術(shù)質(zhì)量與安全分析報告模板
- 常用藥物配伍禁忌表
評論
0/150
提交評論