18.给定程序中,函数fun的功能是:读自然数1~10以及它们的平方根写到名为myfile3.txt的文本文件中,然后再顺序读出显示在屏幕上。 #include
{ FILE *fp; int i,n; float x;
if((fp=fopen(fname, \ return 0;
for(i=1;i<=10;i++)
/**********found**********/
fprintf(___1___,\ printf(\/**********found**********/ ___2___;
printf(\/**********found**********/
if((fp=fopen(___3___,\ return 0;
fscanf(fp,\ while(!feof(fp))
{printf(\
fscanf(fp,\ } fclose(fp); return 1;}
main(){ char fname[]=\ fun(fname);}
第一空:fp 第二空:fclose(fp) 第三空:fname
19.给定程序的功能是:从键盘输入若干行文本(每行不超过80个字符),写到文件myfile4.txt中,用-1作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和WriteText实现。
#include
{FILE *fp;
if((fp=fopen(\ { printf(\ } WriteText(fp); fclose(fp);
if((fp=fopen(\ { printf(\ } ReadText(fp); fclose(fp);}
/**********found**********/ void WriteText(FILE ___1___) { char str[81];
printf(\ gets(str);
while(strcmp(str,\/**********found**********/
fputs(___2___,fw); fputs(\ gets(str); }}
void ReadText(FILE *fr) { char str[81];
printf(\ fgets(str,81,fr); while( !feof(fr) ) {
/**********found**********/ printf(\ fgets(str,81,fr); }}
第一空:*fw 第二空:str 第三空:str
20.给定程序的功能是:调用fun函数建立班级通讯录。通讯录中记录每个学生的编号、姓名和电话号码。班级的人数和学生的信息从键盘读入,每个人的信息作为一个数据块写到myfile5.dbf的二进制文件中。 #include
char name[10]; char tel[10]; }STYPE; void check();
/**********found**********/ int fun(___1___ *std){
/**********found**********/ ___2___ *fp; int i;
if((fp=fopen(\ return(0);
printf(\ for(i=0; i /**********found**********/ fwrite(&std[i], sizeof(STYPE), 1, ___3___); fclose(fp); return (1);} main() { STYPE s[10]={ {1,\ {2,\ {4,\ int k; k=fun(s); if (k==1) { printf(\ check(); } else printf(\void check() { FILE *fp; int i; STYPE s[10]; if((fp=fopen(\ { printf(\ printf(\ printf(\ num name tel\\n\ for(i=0; i { fread(&s[i],sizeof(STYPE),1, fp); printf(\ %s %s\\n\s[i].num,s[i].name,s[i].tel); } fclose(fp);} 第一空:STYPE 第二空:FILE 第三空:fp 21.给定程序的功能是用冒泡法对6个字符进行排序 #include for (i = 0 ; i < 5 ; i++ ) { for (j = i + 1; j < 6; j++) { /**************found**************/ if(strcmp(*(pstr+i),___1___)>0) { p = *(pstr + i) ; /**************found**************/ pstr[i] = ___2___ ; /**************found**************/ *(pstr + j) = ___3___ ; }} }} main( ) { int i ; char *pstr[6], str[6][MAXLINE] ; for(i = 0; i < 6 ; i++) pstr[i] = str[i] ; printf( \ for(i = 0 ; i < 6 ; i++) scanf(\ fun(pstr) ; printf(\ for(i = 0 ; i < 6 ; i++) printf(\第一空:*(pstr+j)或pstr[j] 第二空:*(pstr+j)或pstr[j] 第三空:p 22.给定程序的功能是将十进制整数m转换成k进制(2≤k≤9)数的数字输出。例如,如果输入8和2,则应该输出1000。 #include for( i = 0; m; i++ ) { /**********found**********/ aa[i] = ___1___; /**********found**********/ m /= ___2___; } for( ; i; i-- ) /**********found**********/ printf( \main(){ int b, n; printf( \ scanf( \ fun( n, b );} 第一空;m%k 第二空:k 第三空:aa 23.给定程序的功能是将未在字符串s中出现、而在字符串t中出现的字符,形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,但是去掉重复字符。例如:当s=”12345”,t=”24677”,u中的字符为”67” #include void fun (char *s, char *t, char *u) { int i, j, sl, tl, k, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; i { for (j=0; j if (t[i] == s[j]) break; if (j>=sl) { for (k=0; k /************found************/ u[ul++] = ___2___ ; } } /************found************/ ___3___='\\0';} main(){ char s[100], t[100], u[100]; printf(\scanf(\ printf(\scanf(\ fun(s, t, u); printf(\ 第一空:break 第二空:t[i] 第三空:u[ul] 24.给定程序的功能是将在字符串s中出现、而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。例如:当s=”112345”,t=”2467”时,u中的字符串为”1135”。 #include void fun (char *s,char *t, char *u) { int i, j, sl, tl; sl = strlen(s); tl = strlen(t); for (i=0; i /************found************/ if (s[i] == t[j]) ___1___ ; if (j>=tl) /************found************/ *u++ = ___2___; } /************found************/ ___3___ = '\\0';} main(){ char s[100], t[100], u[100]; printf(\ scanf(\ printf(\ scanf(\ fun(s, t, u); printf(\ 第一空:break 第二空:s[i] 第三空:*u 25.给定程序的功能是将在字符串s中下标为奇数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符出现的逆序排列(注意0为偶数)。例如:当s=”23516”,t=”1133”。 #include void fun (char *s, char *t) { int i, j, sl; sl = strlen(s); /************found************/ if(sl%2) sl-=2; ___1___ sl--; /************found************/ for (i=sl, j=___2___; i>=0; i-=2) { t[2*j] = s[i]; /************found************/ t[2*j +1] = ___3___ ; j++; } t[2*j]='\\0';} main(){ char s[100], t[100]; printf(\ scanf(\ fun(s, t); printf(\ 第一空:else 第二空:0 第三空:s[i]或t[2*j] 26.给定程序的功能是将大写字母转换对应的小写字母的第五个字母;若小写字母v~z,使小写字母的值减去21。转换后的小写字母作为函数值返回。例如,若形参使字母A,则转换为小写字母f;若形参为字母W,则转换为小写字母b。 #include { if( c>='A' && c<='Z') c=c+32; if(c>='a' && c<='u') /**************found**************/ c=c+___1___; else if(c>='v'&&c<='z') c=c-21; /**************found**************/ return ___2___ ;} main(){ char c1,c2; printf(\ \ c1=getchar(); if( isupper( c1 ) ) { /**************found**************/ c2=fun(___3___); printf(\letter \\'%c\\' change to \\'%c\\'\\n\c1,c2); } else printf(\第一空:5 第二空:c 第三空:c1 27.给定程序的功能是计算s=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+ …f(n)的值。例如,当n为5时,函数值应该为:10.407143。 ┌(x+1)/(x-2) x>0 f(x)= ┤0 x=0或x=2 └(x-1)/(x-2) x<0 #include if (x == 0.0 || x == 2.0) /************found************/ return ___1___; else if (x < 0.0) return (x -1)/(x-2); else return (x +1)/(x-2);} double fun( int n ) { int i; double s=0.0, y; /************found************/ for (i= -n; i<=___2___; i++) {y=f(1.0*i); s += y;} /************found************/ return ___3___;} main ( ){ printf(\第一空: 0 第二空:n 第三空:s 28.给定程序的功能是求二分之一的圆面积,函数通过形参得到圆的半径,函数返回二分之一的圆面积。例如输入圆的半径值为:19.527输入为:s=598.950017。 #include {/**********found**********/ return 3.14159 * ___1___ /2.0;} main ( ) /**********found**********/ { ___2___ x; printf ( \ x: \/**********found**********/ scanf ( \ printf (\ 第一空:r*r 第二空:float 第三空:&x 29.给定程序的功能是将既在字符串s中出现、又在字符串t中出现的字符形成一个新字符串放在u中,u中字符按原字符串中字符顺序排列,但去掉重复字符。例如:当s=”42562”,t=”34”,u中的字符串为:”5”。 #include void fun (char *s, char *t, char *u) { int i, j, sl, tl, k, ul=0; sl = strlen(s); tl = strlen(t); for (i=0; i { for (j=0; j if (s[i] == t[j]) break; if(j { for (k=0; k /************found************/ u[ul++]=___2___ ; }} /************found************/ ___3___ = '\\0';} main(){ char s[100], t[100], u[100]; printf(\ scanf(\ printf(\ scanf(\fun(s, t, u); printf(\ 第一空:== 第二空:s[i] 第三空:u[ul] 30.给定程序的功能是从字符串s尾部开始,按逆序把相邻的两个字符交换位置,并一次把每个字符紧随其后重复出现一次,放在一个新串t中。例如:当s中的字符串为:“12345”时,则t中的字符串应为:“4455223311”。 #include void fun (char *s, char *t) { int i, j, sl; /************found************/ sl = ___1___; for (i=sl-1, j=0; i>=0; i-=2) { if (i-1 >= 0) t[j++] = s[i-1]; if (i-1 >= 0) t[j++] = s[i-1]; t[j++] = s[i]; t[j++] = s[i]; } /************found************/ ___2___;} main() { char s[100], t[100]; printf(\/************found************/ scanf(\ fun(s, t); printf(\第一空:strlen(s) 第二空:t[j]=0 第三空: s 31.给定程序的功能是将仅在字符串s中出现而不在字符中t中出现的字符,和仅在字符串t中出现而不在字符串s中出现的字符,构成一个新字符串放在u中,u中的字符按原字符串s中字符顺序排列,不去掉重复字符。例如:当s中字符串为:“112345”时,t=“24677”时,u中的字符串应为:“1135677”。 #include void fun (char *s, char *t, char *u) { int i, j, sl, tl; sl = strlen(s); tl = strlen(t); for (i=0; i { for (j=0; j if (s[i] == t[j]) break; /************found************/ if (j ___1___ tl) *u++ = s[i]; } for (i=0; i { for (j=0; j if (t[i] == s[j]) break; /************found************/ if (j ___2___ sl) *u++ = t[i]; } /************found************/ ___3___ = '\\0';} main() { char s[100], t[100], u[100]; printf(\ scanf(\ printf(\ scanf(\ fun(s, t, u); printf(\第一空:== 第二空:=== 第三空:*u 32.给定程序的功能是将在字符串s中出现、而未在字符串t中出现的字符,构成一个新的字符串放在u中,u中字符按原字符串中字符顺序的逆序排列,不去掉重复字符。例如:当s中的字符串为:“112345”时,t=“24677”,u中的字符串应为:“5311” #include void fun (char *s, char *t, char *u) { int i, j, sl, tl, ul; char r, *up=u; sl = strlen(s); tl = strlen(t); for (i=0; i { for (j=0; j /************found************/ if (s[i] == t[j]) ___1___ ; /************found************/ if(j ___2___ tl) *u++ = s[i]; } *u = '\\0'; ul = strlen(up); for (i=0; i /************found************/ r = ___3___ ; up[i] = up[ul-1-i]; up[ul-1-i] = r; }} main() { char s[100], t[100], u[100]; printf(\ scanf(\ printf(\ scanf(\ fun(s, t, u); printf(\ 第一空:break 第二空:== 第三空:up[i] 33.给定程序的功能是计算并输入下列级数的前N项之和S(N),直到S(N+1)大于q为止,q的值通过形参传入 S?N??21?32?43???N?1N例如:若q的值为50.0,则函数值为50.416687。 #include double fun( double q ) { int n; double s; n = 2; s = 2.0; /************found************/ while (s ___1___ q) { s=s+(double)(n+1)/n; /************found************/ ___2___ ; } printf(\ /************found************/ ___3___ ;} main ( ){ printf(\ 第一空:<= 第二空:n++; 第三空: return s 34.给定程序的功能是求K!(K<13),并通过函数名传回主函数。例如:若K=10,则应该输入:3628800 。 #include {/************found************/ if (k ___1___ 0) /************found************/ return (k*fun(___2___)); /************found************/ else if ( k ___3___ 0 ) return 1L;} main() { int k = 10 ; printf(\第一空:> 第二空:k-1 第三空:== 35.给定程序的功能是读入一个整数K(2≤k≤10000),打印它的所有质因子(就是所有为素数的因子)。例如:若输入整数:3410,则应输出:2、5、11、13。 #include { int i, m; m = 1; for ( i = 2; i < n; i++ ) /************found************/ if (!( n ___1___ i )) { /************found************/ m = 0; ___2___ ; } return ( m );} main( ){ int j, k; printf( \enter an integer number between 2 and 10000: \ /************found************/ scanf( \ printf( \ for( j = 2; j <= k; j++ ) if( ( !( k%j ) )&&( IsPrime( j ) ) ) printf( \ printf(\ 第一空:% 第二空:break 第三空:&k 36.给定程序的功能是分别统计字符串中大写字母和小写字母的个数。 #include void fun ( char *s, int *a, int *b ) { while ( *s ) { if ( *s >= 'A' && *s <= 'Z' ) /**********found**********/ ___1___ ; if ( *s >= 'a' && *s <= 'z' ) /**********found**********/ ___2___ ; s++; }} main( ){ char s[100]; int upper = 0, lower = 0 ; printf( \ \ gets ( s ); fun ( s, & upper, &lower ); /**********found**********/ printf( \ lower = %d\\n\第一空: (*a)++ 第二空:(*b)++ 第三空:upper,lower 37.给定程序的功能是判断字符ch是否与串str中的某个字符相同;若相同,什么也不做,若不同,则插在串的最后。 #include void fun(char *str, char ch ) { while ( *str && *str != ch ) str++; /**********found**********/ if ( *str ___1___ ch ) { str [ 0 ] = ch; /**********found**********/ ___2___ = 0; }} main( ){ char s[81], c ; printf( \ gets ( s ); printf (\ c = getchar(); /**********found**********/ fun(___3___) ; printf( \ is %s\\n\ s);} 第一空:!= 第二空:*(str+1)或*(++str) 第三空: s,c 38.给定程序的功能是根据形参m(2≤m≤9),在二维数组中存放一张m行m列的表格,由main()函数输出。例如:若输入 3 则输出: 1 2 3 2 4 6 3 6 9 #include int a[M][M] = {0} ; fun(int a[][M], int m) { int j, k ; for (j = 0 ; j < m ; j++ ) for (k = 0 ; k < m ; k++ ) /**************found**************/ ___1___ = (k+1)*(j+1);} main ( ) { int i, j, n ; printf ( \ scanf (\=ul)
=ul)