程序填空题

更新时间:2024-04-25 05:24:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

程序填空题

1.给定程序中,函数fun的功能是:求出形参ss所指

字符串数组中最长字符串的长度,其余字符串左边用字符*补齐,使其与最长的字符串等长。字符串数组中共有M个字符串,且串长n) { /**********found**********/ /**********found**********/ void fun(int ___a___, int n) //*a n=len; ___kk___=i;} } //kk { int i, j, max, min, px, pn, t; for(i=0; i

for(j=___len___; j>=0; j--) //len /**********found**********/ ss[i][m--]=ss[i][j]; for (j=___i+1___; j a[j]) //ss[i]][j] { min = a[j]; pn = j; }} main(){char ss[M][N]={\ if (px != i) \{ t = a[i]; a[i] = max; cchongqing\a[px] = t; printf(\ if (pn == i) pn= px; } for(i=0; i

for (i=0; i

2. 给定程序中,函数fun的功能是:求ss所指字符串数 printf(\组中长度最长的字符串所在的行下标,作为函数值返回,printf(\并把其串长放在形参n所指变量中。ss所指字符串数组for (i=0; i

if(i==0) *n=___len___; //len if((fs=fopen(source, ___r___))==NULL) //”r’ return 0; if(len>*n) { if((ft=fopen(target, \/**********found**********/ return 0; ___n=len___; printf(\//*n=len ch=fgetc(fs); k=i; } } return(k);} /**********found**********/ main() while(!feof(___fs__)) // fs { char ss[M][N]={\ { putchar( ch ); \/**********found**********/ cchongqing\ fputc(ch,___ft___); //ft

1

printf(\

for(i=0;i

printf(\leng longest string is : %d\\n\printf(\

ch=fgetc(fs); }

fclose(fs); fclose(ft); printf(\

main(){char sfname[20] =\tfname[20]=\

FILE *myf; int i; char c; myf=fopen(sfname,\

printf(\ for(i=1; i<30; i++)

{c='A'+rand()%;fprintf(myf,\printf(\

fclose(myf);printf(\ if (fun(sfname, tfname))

printf(\ else printf(\

x2xnf(x)?1?x????

2!n!xn?10?6。若x=2.5,函数值为:12.182494。 直到n!double fun(double x) { double f, t; int n; /**********found**********/ f = 1.0+___x___; t = x; n = 1; do {

n++;

/**********found**********/ t *= x/___n___;

/**********found**********/ f += ___t___;

} while (fabs(t) >= 1e-6); return f;}

main(){ double x, y; x=2.5; y = fun(x);

printf(\

printf(\第一空:x 第二空:n 第三空:t

5. 用筛选法可得到2~n(n<10000)之间的所有素数,方

法是:首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所表倍数;依次类推,直到所找的下一个数等于n为止。这样会得一个序列:2,3,5,7,11,13,17,19,23??函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。

int fun(int n)

{ int a[10000], i,j, count=0; for (i=2; i<=n; i++) a[i] = i; i = 2; while (i

/**********found**********/

for (j=a[i]*2; j<=n; j+=___a[i] ___) a[j] = 0; i++;

/**********found**********/ while (___a[i]___==0) i++; }

printf(\ for (i=2; i<=n; i++)

/**********found**********/ if (a[i]!=___0___) {count++;

printf( count?\ return count;}

main(){ int n=20, r;r = fun(n);

printf(\第一空:a[i] 第二空:a[i] 第三空0

8. 给定程序中,函数fun的功能是:对形参ss所指字

符串数组中的M个字符串按长度由短到长进行排序。ss所指字符串数组中共有M个字符串,且串长

void fun(char (*ss)[N])

{ int i, j, k, n[M]; char t[N]; for(i=0; i

/**********found**********/

for(j=___i+1___; j

if(n[k]>n[j]) ___k=j___; if(k!=i)

{ strcpy(t,ss[i]);

strcpy(ss[i],ss[k]);

6.函数fun的功能是:从三个形参a,b,c中找出中间/**********found**********/ 的那个数,作为函数值返回。例如:当a=3,b=5,c=4时, strcpy(ss[k],___t__); 中数为4。 n[k]=n[i]; } }} int fun(int a, int b, int c) main() { int t; { char ss[M][N]={\/**********found**********/ \ t = (a>b) ? (b>c? b :(a>c?c:___a___)) : int i; ((a>c)?___a___ : ((b>c)?c:___b___)); printf(\ return t;} for(i=0; i

for(i=0; i

7. 函数fun的功能是:计算

printf(\

第一空:i+1 第二空:k=j 第三空:t

2

9. 函数fun的功能是:把形参a所指数组中的最小值放

在元素a[0]中,接着把形参a所指数组中的最大值放在a[1]元素中;再把a所指数组元素中的次小值放在a[2]中,把a所指数组元素中的次大值放在a[3];其余以此类推。例如:若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7;则按规则移动后,数据排列为:1、9、2、8、3、7、4、6、5。形参n中存放a所指数组中数据的个数。

#define N 9

void fun(int a[], int n)

{ int i,j, max, min, px, pn, t; for (i=0; i

{/**********found**********/ max = min = ___a[i]___; px = pn = i;

for (j=i+1; j

{ max = a[j]; px = j; } /**********found**********/ if (min>___a[j]___)

{ min = a[j]; pn = j; } } if (pn != i)

{ t = a[i]; a[i] = min; a[pn] = t; if (px == i) px =pn; } if (px != i+1)

{ t = a[i+1]; a[i+1] = max; a[px] = t; } }} main()

{ int b[N]={9,1,4,2,3,6,5,8,7}, i; printf(\

for (i=0; i

printf(\ for (i=0; i

第一空:a[i] 第二空:a[j] 第三空:a[j]

___max.name___,max.age);}

第一空:*std 第二空:std[i].age 第三空:max.name

11.给定程序中,函数fun的功能是:将s所指字符串

中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。例如,形参s所指的字符串为:def35adh3kjsdf7。执行结果为:defadhkjsdf3537。 void fun(char *s) { int i, j=0, k=0; char t1[80], t2[80];

for(i=0; s[i]!='\\0'; i++)

if(s[i]>='0' && s[i]<='9'){ /**********found**********/

t2[j]=s[i]; __j++___; } else t1[k++]=s[i]; t2[j]=0; t1[k]=0;

/**********found**********/

for(i=0; i

for(i=0; i<___j___; i++) s[k+i]=t2[i];} main()

{ char s[80]=\ printf(\ fun(s);

printf(\第一空:j++; 第二空:s[i]=t1[i];第三空:j

12. 函数fun的功能是:把形参a所指数组中的奇数原

顺序依次放到a[0]、a[1]、a[2]、??中,把偶数从数组中删除,奇数个数通过函数值返回。例如:若a所指数组中数据最初排列为:9、1、4、2、3、6、5、8、7,删除偶数后a所指数组中数据为:9、1、3、5、7,返回值为5。

#define N 9

int fun(int a[], int n) { int i,j; j = 0;

for (i=0; i

/**********found**********/ if (a[i]%2==___1___){ /**********found**********/

a[j] = a[i]; ___j++___; } /**********found**********/ return ___j___;} main()

{ int b[N]={9,1,4,2,3,6,5,8,7}, i, n; printf(\ for (i=0; i

printf(\ printf(\ for (i=0; i

printf(\第一空:1 第二空:j++ 第三空j

10. 给定程序中,函数fun的功能是:将形参std所指

结构体数组中年龄最大者的数据作为函数值返回,并在main函数中输出。 typedef struct { char name[10]; int age; }STD;

STD fun(STD std[], int n) { STD max; int i; /**********found**********/ max= ___*std_;

for(i=1; i

/**********found**********/

if(max.age<___std[i].age__) max=std[i]; return max;} main( )

{ STD std[5]={\

\ STD max; max=fun(std,5); printf(\/**********found**********/

printf(\

3

13. 给定程序中,函数fun的功能是:对形参s所指字

符串下标为奇数的字符按ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参p所指字符数组中,形成一个新串。例如,形参s所指的字符串为:

baawrskjghzlicda,执行后p所指字符数组中的字符串应为:aachjlsw。

void fun(char *s, char *p) { int i, j, n, x, t; n=0;

for(i=0; s[i]!='\\0'; i++) n++; for(i=1; i

/**********found**********/

for(j=___i___+2 ; js[j]) t=j; if(t!=i)

{ x=s[i]; s[i]=s[t]; s[t]=x; }}

for(i=1,j=0; i

{ char s[80]=\ printf(\ fun(s,p);

printf(\第一空:t=i 第二空:i 第三空 0

{ str[ j ]= str[i]; ___j++___; } else k++;

/***************found**************/ str[j]=___0___ ;

/***************found**************/ return( ___k___ );} main(){

char string[81], x; clrscr();

printf(\ gets(string);

printf(\ scanf(\

printf( \deleting %d '%c'(s), the string becomes:\\n%s\\n\x), x, string);}

第一空:j++ 第二空:0 第三空:k

16. 给定程序中已建立一个带有头结点的单向链表,链

表中的各结点按结点数据域中的数据从小到大顺序链接。函数fun的功能是:把形参x的值放入一个新结点并插入到链表中,插入后各结点仍保持从小到大顺序排序。 #define N 8

14. 给定函数int MySearch(char *str,char *s)的功typedef struct list 能是:统计字符串s在字符串str中出现的次数。例如,{ int data; 若输入字符串”12 123 12345”和”23”,则应输出2(表 struct list *next; 示字符串”23”在字符串”12 123 12345”中出现了两} SLIST;

次)。若输入字符串”33333”和”33”,则应输出4(表void fun( SLIST *h, int x) 示字符串”33”在字符串”33333”出现了四次)。 { SLIST *p, *q, *s; int MySearch( char* str, char* s ){ s=(SLIST *)malloc(sizeof(SLIST)); char* p; /**********found**********/ int n =0; s->data=___x___; for( ; *str; ) q=h; /***************found***************/ p=h->next;

if( ( p = strstr( str, s ) ) != ___NULL___ ) while(p!=NULL && x>p->data) { { n++; str=p+1; } /**********found**********/ else q=___p___; /***************found***************/ p=p->next; } ___*str___; s->next=p; /***************found***************/ /**********found**********/ return( ___n___ );} q->next=__s__;} main() SLIST *creatlist(int *a) { char str1[81], str2[21]; { SLIST *h,*p,*q; int i; printf(\ h=p=(SLIST *)malloc(sizeof(SLIST)); gets(str1); for(i=0; idata=a[i]; p->next=q; p=q; printf( \are(is) appeared in str1 %d } times\\n\ p->next=0; 第一空:NULL 第二空:*str=0 第三空:n return h;}

void outlist(SLIST *h)

15. 给定函数 char *MyDelete(char *str,char c)的{ SLIST *p; 功能是:在字符串str中删除变量c中的字符,有几个删 p=h->next; 几个,并返回所删字符的个数。例如,若输入字符串”ab if (p==NULL) abc bcdef”和字符’b’,则应输出字符串”a ac printf(\cdef”和3(表示删了3个字符’b’)。 else int MyDelete( char* str, char c ) { printf(\{ int i, j=0, k=0; do{printf(\ for( i = 0; str[i]; i++ ) while(p!=NULL); if( str[i] != c ) printf(\/***************found**************/

4

main()

{ SLIST *head; int x;

int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a);

printf(\

outlist(head);

printf(\

scanf(\ fun(head,x);

printf(\ outlist(head);}

第一空:x 第二空:p 第三空:s

17. (4)给定程序的功能是:调用函数fun将指定源文

件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制过程中,把复制的内容输出到终端屏幕。主函数中源文件名放在变量sfname中,目标文件名放在变量tfname中。 int fun(char *source, char *target) { FILE *fs,*ft; char ch; /**********found**********/

if((fs=fopen(source, ___r___))==NULL) return 0;

if((ft=fopen(target, \ return 0;

printf(\ ch=fgetc(fs);

/**********found**********/ while(!feof(___fs___)) { putchar( ch );

/**********found**********/ fputc(ch,___ft___); ch=fgetc(fs); }

fclose(fs); fclose(ft); printf(\ return 1;} main()

{ char sfname[20] =\

tfname[20]=\

FILE *myf; int i; char c; myf=fopen(sfname,\

printf(\ for(i=1; i<30; i++)

{c='A'+rand()%;fprintf(myf,\printf(\

fclose(myf);printf(\ if (fun(sfname, tfname)) printf(\ else printf(\

第一空: “r” 第二空:fs 第三空:ft

18. 给定程序中,函数fun的功能是:读自然数1~10以及它们的平方根写到名为myfile3.txt的文本文件中,然后再顺序读出显示在屏幕上。 int fun(char *fname )

{ FILE *fp; int i,n; float x; if((fp=fopen(fname, \ return 0;

for(i=1;i<=10;i++)

/**********found**********/

fprintf(__fp__,\

5

printf(\/**********found**********/ ___fclose(fp)___;

printf(\/**********found**********/

if((fp=fopen(___fname___,\ 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实现。

void WriteText(FILE *); void ReadText(FILE *); main()

{FILE *fp;

if((fp=fopen(\ { printf(\ WriteText(fp); fclose(fp);

if((fp=fopen(\ { printf(\ ReadText(fp); fclose(fp);}

/**********found**********/

void WriteText(FILE ___*fw___) { char str[81];

printf(\ gets(str);

while(strcmp(str,\/**********found**********/

fputs(___str___,fw); fputs(\ gets(str); }}

void ReadText(FILE *fr) { char str[81];

printf(\file and output to screen :\\n\ fgets(str,81,fr); while( !feof(fr) ) { /**********found**********/ printf(\str___); fgets(str,81,fr); }}

第一空:*fw 第二空:str 第三空:str

20. 给定程序的功能是:调用

fun函数建立班级通讯

录。通讯录中记录每个学生的编号、姓名和电话号码。班级的人数和学生的信息从键盘读入,每个人的信息作为一个数据块写到myfile5.dbf的二进制文件中。 #define N 5 typedef struct { int num;

char name[10]; char tel[10]; }STYPE;

void check();

/**********found**********/ int fun(___STYPE___ *std){ /**********found**********/ ___FILE___ *fp; int i;

if((fp=fopen(\ return(0);

printf(\ for(i=0; i

/**********found**********/

fwrite(&std[i], sizeof(STYPE), 1, ___fp___); fclose(fp); return (1);} main()

{ STYPE s[10]={ {1,\

{2,\

{4,\ int k; k=fun(s); if (k==1)

{ printf(\ else printf(\void check()

{ FILE *fp; int i; STYPE s[10]; if((fp=fopen(\ { printf(\

printf(\file and output to screen :\\n\ printf(\ for(i=0; i

{ fread(&s[i],sizeof(STYPE),1, fp);

printf(\

s[i].num,s[i].name,s[i].tel); } fclose(fp);}

第一空:STYPE 第二空:FILE 第三空:fp

第二空:*(pstr+j)或pstr[j] 第三空:p

22.给定程序的功能是将十进制整数

m转换成k进制

(2≤k≤9)数的数字输出。例如,如果输入8和2,则应该输出1000。 #include

void fun( int m, int k ) { int aa[20], i;

for( i = 0; m; i++ ) { /**********found**********/ aa[i] = ___m%k___;

/**********found**********/ m /= __k___; } for( ; i; i-- )

/**********found**********/

printf( \aa___[ i-1 ] );} 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 #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

21. 给定程序的功能是用冒泡法对6个字符进行排序 if (t[i] == s[j]) break;

if (j>=sl) #include

{ for (k=0; k

/************found************/ fun ( char *pstr[6])

if (t[i] == u[k]) ___break___ ; { int i, j ;char *p ;

if (k>=ul) for (i = 0 ; i < 5 ; i++ ) {

/************found************/ for (j = i + 1; j < 6; j++) {

u[ul++] = ___t[i]__ ; /**************found**************/

} } if(strcmp(*(pstr+i),___*(pstr+j)___)>0)

/************found************/ { p = *(pstr + i) ;

___u[ul]___='\\0';} /**************found**************/

main(){ char s[100], t[100], u[100]; pstr[i] = ___*(pstr+j)___ ;

printf(\/**************found**************/

scanf(\ *(pstr + j) = ___p___ ; }} }}

printf(\main( )

scanf(\{ int i ;

fun(s, t, u); char *pstr[6], str[6][MAXLINE] ;

printf(\ for(i = 0; i < 6 ; i++) pstr[i] = str[i] ;

printf( \6 str(1 str at each line): \\n\) ; 第一空:break 第二空:t[i] 第三空:u[ul]

for(i = 0 ; i < 6 ; i++) 24.给定程序的功能是将在字符串s中出现、而未在字scanf(\符串t中出现的字符形成一个新的字符串放在u中,u fun(pstr) ; 中字符按原字符串中字符顺序排列,不去掉重复字符。 printf(\例如:当s=”112345”,t=”2467”时,u中的字符串

for(i = 0 ; i < 6 ; i++) 为”1135”。 printf(\#include 第一空:*(pstr+j)或pstr[j] #include

6

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]) ___break___ ; if (j>=tl)

/************found************/ *u++ = ___s[i]___; } /************found************/ ___*u___ = '\\0';} main(){

char s[100], t[100], u[100];

printf(\ scanf(\

printf(\ scanf(\ fun(s, t, u);

printf(\第一空:break 第二空:s[i] 第三空:*u

c=c-21;

/**************found**************/ return __c__ ;} main(){ char c1,c2;

printf(\ c1=getchar();

if( isupper( c1 ) ) {

/**************found**************/ c2=fun(___cl___);

printf(\letter \\'%c\\' change to \\'%c\\'\\n\c1,c2); }

else printf(\第一空:5 第二空:c 第三空:c1

给定程序的功能是计算

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 #include

25.给定程序的功能是将在字符串s中下标为奇数位置float f( double x){

上的字符,紧随其后重复出现一次,放在一个新串t中, if (x == 0.0 || x == 2.0) t中字符按原字符串中字符出现的逆序排列(注意0为偶/************found************/ 数)。例如:当s=”23516”,t=”1133”。 return ___0__; #include else if (x < 0.0) #include return (x -1)/(x-2); void fun (char *s, char *t) else { int i, j, sl; return (x +1)/(x-2);} sl = strlen(s); double fun( int n ) /************found************/ { int i; double s=0.0, y; if(sl%2) sl-=2; ___else___ sl--; /************found************/ /************found************/ for (i= -n; i<=___n___; i++) for (i=sl, j=___0___; i>=0; i-=2) {y=f(1.0*i); s += y;} { t[2*j] = s[i]; /************found************/ /************found************/ return ___s__;} t[2*j +1] = ___s[i]___ ; main ( ){ printf(\ j++; } 第一空: 0 第二空:n 第三空:s t[2*j]='\\0';}

28.给定程序的功能是求二分之一的圆面积,函数通过main(){ char s[100], t[100];

形参得到圆的半径,函数返回二分之一的圆面积。例如 printf(\

输入圆的半径值为:19.527输入为:s=598.950017。 scanf(\

#include fun(s, t);

float fun ( float r ) printf(\

{/**********found**********/ 第一空:else 第二空:0 第三空:s[i]或t[2*j]

return 3.14159 * ___r*r___ /2.0;}

26.给定程序的功能是将大写字母转换对应的小写字母main ( ) 的第五个字母;若小写字母v~z,使小写字母的值减去/**********found**********/ 21。转换后的小写字母作为函数值返回。例如,若形参{ ___float___ x;

使字母A,则转换为小写字母f;若形参为字母W,则转换 printf ( \为小写字母b。 /**********found**********/ #include scanf ( \&x___ ); #include printf (\char fun(char c) 第一空:r*r 第二空:float 第三空:&x { if( c>='A' && c<='Z')

29.给定程序的功能是将既在字符串s中出现、又在字 c=c+32;

符串t中出现的字符形成一个新字符串放在u中,u中字 if(c>='a' && c<='u')

符按原字符串中字符顺序排列,但去掉重复字符。例如:/**************found**************/

当s=”42562”,t=”34”,u中的字符串为:”5”。 c=c+___5___;

#include else if(c>='v'&&c<='z')

7

27.

#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

if (s[i] == t[j]) break; if(j

{ for (k=0; k

if (s[i] _1_ u[k]) break; if (k>=ul)

/************found************/

u[ul++]=___s[i]___ ; }} /************found************/ ___u[ul]___ = '\\0';}

main(){ char s[100], t[100], u[100]; printf(\scanf(\

printf(\ scanf(\fun(s, t, u);

printf(\第一空:== 第二空:s[i] 第三空:u[ul] sl = strlen(s); tl = strlen(t); for (i=0; i

if (s[i] == t[j]) break; /************found************/ if (j ___1___ tl) *u++ = s[i]; } for (i=0; i

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

30.给定程序的功能是从字符串

s尾部开始,按逆序把

相邻的两个字符交换位置,并一次把每个字符紧随其后重复出现一次,放在一个新串t中。例如:当s中的字符串为:“12345”时,则t中的字符串应为:“4455223311”。 #include #include

void fun (char *s, char *t) { int i, j, sl;

/************found************/ sl = ___strlen(s)___;

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]; } /************forund************/ ___t[j]=0___;} main()

{ char s[100], t[100];

printf(\/************found************/ scanf(\s__); fun(s, t);

printf(\第一空:strlen(s) 第二空:t[j]=0 第三空: s

32.给定程序的功能是将在字符串s中出现、而未在字

符串t中出现的字符,构成一个新的字符串放在u中,u中字符按原字符串中字符顺序的逆序排列,不去掉重复字符。例如:当s中的字符串为:“112345”时,t=“24677”,u中的字符串应为:“5311” #include #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

if (s[i] == t[j]) ___1___ ; /************found************/ if(j ___2___ tl) *u++ = s[i]; } *u = '\\0';

ul = strlen(up);

for (i=0; i

    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]

    31.给定程序的功能是将仅在字符串s中出现而不在字

    符中t中出现的字符,和仅在字符串t中出现而不在字符串s中出现的字符,构成一个新字符串放在u中,u中的字符按原字符串s中字符顺序排列,不去掉重复字符。例如:当s中字符串为:“112345”时,t=“24677”时,u中的字符串应为:“1135677”。 #include #include

    void fun (char *s, char *t, char *u) { int i, j, sl, tl;

    8

    33.给定程序的功能是计算并输入下列级数的前N项之

    和S(N),直到S(N+1)大于q为止,q的值通过形参传入

    234N?1S?N???????例如:若q的值为50.0,

    123N则函数值为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

    写字母的个数。

    #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( \第一空: (*a)++ 第二空:(*b)++ 第三空:upper,lower

    34.给定程序的功能是求

    K!(K<13),并通过函数名传回

    主函数。例如:若K=10,则应该输入:3628800 。 #include long fun ( int k)

    {/************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 第三空:==

    37.给定程序的功能是判断字符ch是否与串str中的某

    个字符相同;若相同,什么也不做,若不同,则插在串的最后。

    #include #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( \enter a string:\\n\); gets ( s ); printf (\ c = getchar();

    /**********found**********/ fun(___3___) ;

    printf( \第一空:!= 第二空:*(str+1)或*(++str) 第三空: s,c

    35.给定程序的功能是读入一个整数

    K(2≤k≤10000),

    打印它的所有质因子(就是所有为素数的因子)。例如:若输入整数:3410,则应输出:2、5、11、13。 #include IsPrime ( int n )

    { 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( \2 and 10000: \

    /************found************/ scanf( \

    printf( \k );

    for( j = 2; j <= k; j++ )

    if( ( !( k%j ) )&&( IsPrime( j ) ) ) printf( \ printf(\

    第一空:% 第二空:break 第三空:&k

    38.给定程序的功能是根据形参m(2≤m≤9),在二维数

    组中存放一张m行m列的表格,由main()函数输出。例如:若输入 3

    则输出: 1 2 3

    2 4 6 3 6 9

    #include #define M 10

    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 (\

    /**************found**************/

    9

    36.给定程序的功能是分别统计字符串中大写字母和小

    fun ( ___2___ ) ;

    for ( i = 0 ; i < n ; i++) { for (j = 0 ; j < n ; j++) /**************found**************/ printf ( \ printf ( \

    第一空:a[j][k] 第二空:a,n 第三空:a[i][j]

    printf(\

    第一空:n 第二空:else 第三空:a,b

    41.给定程序的功能是求出1到1000之内能被7或11

    整除但不能同时被7和11整除的所有整数放存数组a中,通过n返回这些数的个数。 #include

    void fun(int *a, int *n)

    39.给定程序的功能是对a数组中n个人员的工资进行{ int i, j = 0 ;

    分段统计,各段的人数存到b数组中;工资为1000元以下 for(i = 1 ; i <= 1000 ; i++) { 的人数存到b[0]中, 工资为1000元到1999元的人数存/**************found**************/ 到b[1]中, 工资为2000元到2999元的人数存到b[2], if(((i % 7 == 0) || (i % 11 == 0)) && i % 77 != 工资为3000元到3999元的人数存到b[3], 工资为40000) a[j++] = ___1___ ; }

    元到4999元的人数存到b[4],工资为5000元以上的人/**************found**************/ 数存到b[5]中。例如,当a数组中的数据为:900、1800、 *n = ___2___ ;} 2700、3800、5900、3300、2400、7500、3800,调用该main() 函数后,b中存放的数据应是:1、1、2、3、0、2 { int aa[1000], n, k ; #include /**************found**************/ void fun(int a[], int b[], int n) fun ( ___3___ ) ; { int i; for ( k = 0 ; k < n ; k++ ) /**************found**************/ if((k + 1) % 10 == 0) printf(\ for (i=0; i<6; i++) b[i] = ___1___; else printf(\ for (i=0; i= 5000) b[5]++;

    42.给定程序中已经建立一个带有头结点的单向链表,/**************found*************/

    在main函数中将多次调用fun函数,每调用一次fun函 ___2___ b[a[i]/1000]++;}

    数,输出链表尾部结点中的数据,并释放该结点,使链表main()

    { int i, a[100]={ 900, 1800, 2700, 3800, 5900, 缩短。

    #include 3300, 2400, 7500, 3800}, b[6];

    #include fun(a, b, 9);

    #define N 8 printf(\

    typedef struct list /**************found**************/

    { int data; for (i=0; i<6; i++)

    struct list *next; printf(\

    } SLIST; printf(\

    void fun( SLIST *p) 第一空:0 第二空:else 第三空:b[i]

    { SLIST *t, *s;

    40.给定程序的功能是将n个人员的考试成绩进行分段 t=p->next; s=p;

    统计,考试成绩放在a数组中,各分数段的人数存到b while(t->next != NULL) 数组中:成绩为60到69的人数存到b[0], 成绩为70 { s=t;

    到79的人数存到b[1], 成绩为80到89的人数存到b[2], /**********found**********/ 成绩为90到99的人数存到b[3],成绩为100的人数存 t=t->___1___; }

    到b[4],成绩为60分以下的人数存到b[5]中。例如,当/**********found**********/ a数组中的数据是:93、85、77、68、59、43、94、75、 printf(\98。调用该函数后,b数组中存放的数据应是:1、2、1、 s->next=NULL; 3、0、2。 /**********found**********/ #include free(___3___);} void fun(int a[], int b[], int n) SLIST *creatlist(int *a) { int i; { SLIST *h,*p,*q; int i; for (i=0; i<6; i++) b[i] = 0; h=p=(SLIST *)malloc(sizeof(SLIST)); /**************found**************/ for(i=0; idata=a[i]; p->next=q; p=q;} /**************found**************/ p->next=0; ___2___ b[(a[i]- 60)/10]++;} return h;} main() void outlist(SLIST *h) { int i, a[100]={ 93, 85, 77, 68, 59, { SLIST *p; 43, 94, 75, 98}, b[6]; p=h->next; /**************found**************/ if (p==NULL) printf(\ fun(___3___, 9); else printf(\ { printf(\ for (i=0; i<6; i++) printf(\ do{printf(\ p=p->next; }

    10

    while(p!=NULL);

    printf(\main(){ SLIST *head;

    int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a);

    printf(\outlist(head);

    printf(\while (head->next != NULL){ fun(head);

    printf(\

    printf(\from head again outlist(head); }}

    第一空:next 第二空:t->data 第三空:t

    45.已知学生的记录由学号和学习成绩构成,N名学生的

    数据已经存入a结构体数组中。给定程序的功能是找出成绩最低的学生记录,通过形参返回主函数。 #include #include #define N 10

    typedef struct ss

    { char num[10]; int s; } STU; fun(STU a[], STU *s)

    {/**************found**************/ ___1___ h; int i ;

    :\\n\ h = a[0];

    for ( i = 1; i < N; i++ )

    /**************found**************/

    if ( a[i].s < h.s ) ___2___ = a[i];

    43.给定程序的功能是计算score中m个人的平均成绩/**************found**************/ aver,将低于aver的成绩放在below中,通过函数名返回 *s = ___3___ ;} 人数。例如,当 main(){STU a[N]={ {\

    socre={10,20,30,40,50,60,70,80,90},m=9时,函数返{\回的人数应该是4,below={10,20,30,40}。 {\#include {\#include int i; int fun(int score[], int m, int below[]) printf(\{ int i, j = 0 ; for ( i=0; i< N; i++ ) float aver = 0.0 ; printf(\ for(i = 0 ; i < m ; i++) aver += score[i] ; fun ( a, &m ); aver /= (float) m ; printf (\ for(i = 0 ; i < m ; i++) printf (\/**************found**************/ 第一空:STU 第二空:h 第三空:h

    if(score[i] < aver) below[j++] = ___1___ ; 46. 给定程序中已经建立一个带有头结点的单项链表, return j ;} 链表中的各结点按照数据域递增有序链接。函数fun的main(){ int i, n, below[9] ; 功能是:函数链表中数据域值相同的结点,使之只保留 int score[9] = {10, 20, 30, 40, 50, 一个。(101) 60, 70, 80, 90} ; #define N 8 /**************found**************/ typedef struct list n = fun(score, 9, ___2___) ; { int data; printf( \ struct list *next; /**************found**************/ } SLIST; for (i = 0 ; i < n ; i++) printf(\\___3___) ;} void fun( SLIST *h) 第一空:score[i] 第二空:below 第三空:below[i] { SLIST *p, *q;

    p=h->next;

    44.给定程序的功能是求出能整除x且不是偶数的各整 if (p!=NULL) 数,并放在数组pp中,这些除数的个数由n返回。例如, { q=p->next; 若x的值为30,则有4个数符合要求,它们是1,3,5,15。 while(q!=NULL) #include { if (p->data==q->data) void fun(int x, int pp[], int *n) { p->next=q->next; { int i, j = 0 ; /**********found**********/ for(i = 1 ; i <= x ; i +=2 ) free(___1___); /**************found**************/ /**********found**********/ if((x % i) == 0) pp[j++] = ___1___ ; q=p->___2___; } /**************found**************/ else *n = ___2___ ;} { p=q; main(){ int x, aa[1000], n, i ; /**********found**********/

    printf( \ q=q->___3___; } } }} scanf(\SLIST *creatlist(int *a) /**************found**************/ { SLIST *h,*p,*q; int i; fun(x, ___3___ ) ; h=p=(SLIST *)malloc(sizeof(SLIST)); for( i = 0 ; i < n ; i++ ) for(i=0; idata=a[i]; p->next=q; p=q; } 第一空: i 第二空: j 第三空:aa,&n

    11

    p->next=0; return h;}

    void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL)

    printf(\ else{ printf(\

    do{printf(\ p=p->next; } while(p!=NULL);

    printf(\main( ){ SLIST *head;

    int a[N]={1,2,2,3,4,4,4,5}; head=creatlist(a);

    printf(\list before deleting :\\n\outlist(head); fun(head);

    printf(\list after deleting :\\n\outlist(head);}

    第一空:q 第二空:next 第三空: next

    case 3: c3++; }

    n /= 10;}}

    main(){ long n=123114350L;

    fun(n); printf(\printf(\n,c1,c2,c3);}

    第一空:n 第二空:break 第三空:break

    49.函数fun的功能是进行字母转换,若形参ch中小写

    英文字母,则转换成参应的大写英文字母;若ch中是大写英文字母,则转换成对应的小写英文字母;若是其它字母则保持不变;并转换后的结果作为函数值返回。 #include #include char fun(char ch)

    {/**********found**********/

    if ((ch>='a')___1___(ch<='z')) return ch -'a' + 'A'; if ( isupper(ch) )

    /**********found**********/

    47.给定程序的功能是实现矩阵(3行3列)的转置。 return ch +'a'-___2___ ; #include /**********found**********/ int fun(int array[3][3]) return ___3___;} { int i,j,arr[3][3] ; main(){ char c1, c2; memcpy(arr, array, 9*sizeof(int)) ; printf(\ for(i = 0 ; i < 3 ; i++) c1='w'; c2 = fun(c1); for(j = 0 ; j < 3 ; j++) printf(\/**************found**************/ c1='W'; c2 = fun(c1); array[i][j] = ___1___ ;} printf(\main(){ int i,j; c1='8'; c2 = fun(c1); int array[3][3]={{100,200,300}, printf(\ {400,500,600}, 第一空:&& 第二空:’A’ 第三空:ch {700,800,900}};

    50.给定程序的功能是对指定字符在字符串a中出现的 for (i=0;i<3;i++)

    次数进行统计,统计的数据存到b数组中。其中:字 { for (j=0;j<3;j++)

    符’Z’ 出现的次数存放到b[0]中,字符’Y’出现的次 printf(\

    数存放到b[1],字符’X’出现的次数存放到b[2]中,字 printf(\

    符’W’出现的次数存放到b[3],字符’V’出现的次数/**************found**************/

    存放到b[4]中,其它字符出现的次数存到b[5]中。 fun(___2___);

    #include printf(\

    #include for (i=0;i<3;i++)

    void fun(char *a, int b[]) { for (j=0;j<3;j++)

    { int i; /**************found**************/

    for (i=0; i<6; i++) b[i] = 0; printf(\

    /**************found**************/ printf(\

    第一空:arr[j][i] 第二空:array 第三空:array[i][j] for (i=0; i< ___1___(a); i++)

    if (a[i] >= 'V' && a[i] <= 'Z')

    48.函数fun的功能是:统计长整数n的各个位上出现 b[4-(a[i]-'V')]++;

    数字1、2、3的次数,并通过上部(全局)变量 c1、c2、/**************found**************/ c3返回主函数。例如:当n=123114350时,结果应该是: ___2___ b[5]++;} c1=3 c2=1 c3=2。 main() #include { int i, b[6]; int c1,c2,c3; char a[100] = \void fun(long n) /**************found**************/ { c1 = c2 = c3 = 0; fun(___3___); while (n) { printf(\/**********found**********/ for (i=0; i<6; i++) printf(\ switch(___1___){ printf(\/**********found**********/ 第一空:strlen 第二空:else 第三空:a,b case 1: c1++;___2___;

    50.函数fun的功能是:将形参a所指数组中的前半部/**********found**********/

    分元素中的值和后半部分元素中的值对换。形参n中存 case 2: c2++;___3___;

    12

    放数组中的数据的个数,若n为奇数,则中间的元素不动。例如:若a所指数组中的数据一次为:1、2、3、4、5、6、7、8、9,则调换后为:6、7、8、9、5、1、2、3、4。

    #include #define N 9

    void fun(int a[], int n) { int i, t, p;

    /**********found**********/

    p = (n%2==0)?n/2:n/2+___1___; for (i=0; i

    /**********found**********/ a[i] = a[p+___2___]; /**********found**********/ ___3___ = t; }} main()

    { int b[N]={1,2,3,4,5,6,7,8,9}, i; printf(\ for (i=0; i

    printf(\ for (i=0; i

    第一空:1 第二空:i 第三空:a[p+i]

    if (high % j ==0 ){

    /************found************/ yes=0; ___2___; }

    if (yes) { sum +=high; n++; } /************found************/ ___3___; } return sum ;} main ( ){

    printf(\

    第一空:&& 第二空:break 第三空:high=high-1

    54.给定程序的功能是删除w数组中下标为k的元素中

    的值。程序中,调用了getindex、arrout和arrdel三个函数,getindex用以输入所删除元素的下标,函数中对输入的下标进行检查,若越界,则要求重新输入,直到正确为止。arrout用以输出数组中的数据,arrdel进行所要求的删除操作。 #include #define NUM 10

    arrout ( int *w, int m ) { int k;

    /************found************/ for (k = 0; k < ___1___; k++) printf (\ printf (\

    arrdel ( int *w, int n, int k ) { int i;

    for ( i = k; i < n-1; i++ ) w[i] = w[i+1]; n--;

    /************found************/

    52.给定程序的功能是把s串中所有的字符前移一个位 return ___2___;} 置,串中的第一个字符移到最后。例如:s串中原有的字getindex( int n ) 符串为:Mn.123xyZ,则调用函数后,s串中的内容为:{ int i; n.123xyZM /************found************/ #include ___3___ #define N 81 { printf(\fun ( char *s ) scanf (\{ char b[N] ; } while( i < 0 || i > n-1 ); sprintf(b, \ return i;} /**************found**************/ main( ) strcpy(___1___) ;} { int n, d, main( ) a[NUM]={21,22,23,24,25,26,27,28,29,30}; { char a[ N ] ; n = NUM;

    printf ( \printf (\ printf ( \original string is : \); puts( a ); arrout ( a, n ); /**************found**************/ d = getindex( n ); n = arrdel ( a, n, d ); fun ( ___2___ ); printf (\the data after delete :\\n\ printf ( \arrout( a, n );} /**************found**************/ 第一空:m 第二空:n 第三空: do ___3___ ( a );}

    55.给定程序的功能是从字符串s尾部开始,按逆序把第一空:s,b 第二空:a 第三空:puts

    在其中出现的每相邻的两个字符,紧随其后重复出现一

    53.给定程序的功能是计算并输出high以内最大的10次,放在一个新串t中,若字符串s中头部有剩余的单个素数和。high由主函数传给fun函数。例如:high值个字符也重复,放在t的最后。例如:当s中的字符串为100,函数的值为732。 为:”12345”时,则t中的字符串应该#include 为:”5454323211” #include #include int fun( int high ) #include { int sum = 0, n=0, j, yes; void fun (char *s, char *t) /************found************/ { int i, j, sl; while ((high >= 2) ___1___ (n < 10)) sl = strlen(s); { yes = 1; for(i=sl-1,j=0;i>=0;i-=2) for (j=2; j<=high/2; j++ ) { t[j++] = s[i];

    13

    if (i-1 >= 0) t[j++] = s[i-1]; /************found************/ t[j++] = ___1___;

    /************found************/ if (i-1 ___2___ 0) t[j++]=s[i-1]; } t[j] = '\\0';} main()

    { char s[100], t[100]; printf(\enter string s:\scanf(\s);

    /************found************/ fun(___3___);

    printf(\第一空:s[i] 第二空:>= 第三空:s,t

    even=fun(head);

    printf(\ outresult(even, stdout);}

    第一空:NODE 第二空:h->next 第三空:p->next

    57.给定程序的功能是把在字符串s中出现的每个字符,

    紧随其后重复出现一次,形成一个新串放在t中,且在t中把原相邻字符的位置进行了互换。例如:当s中的字符串为:”12345”时,则t中的字符串应该为:”2211443355”。 #include #include

    void fun (char *s, char *t) { int i,j,sl;

    /************found************/ sl = ___1___(s);

    for (i=0, j=0; i

    { t[2*j] = s[i+1]; t[2*j +1] = s[i+1];

    j++; }

    t[2*j] = s[i]; t[2*j +1] = s[i]; /************found************/ ___2___; } t[2*sl] = '\\0';} main()

    { char s[100], t[100]; printf(\enter string s:\scanf(\s);

    /************found************/ fun(___3___);

    printf(\第一空:strlen 第二空:j=j+1 第三空:s,t

    56. 给定程序的功能是建立一个带有头结点的单向链

    表,并用随机函数为各结点赋值。函数fun的功能是将单向链表结点(不包括结点)数据域为偶数的值累加起来,并且作为函数值返回。 #include #include typedef struct aa

    { int data; struct aa *next; }NODE; int fun(NODE *h) { int sum = 0 ;

    /***********found**********/ ___1___ *p;

    /***********found**********/ p=___2___; while(p)

    { if(p->data%2==0) sum +=p->data;

    /***********found**********/ p=___3___; } return sum;}

    NODE *creatlink(int n) { NODE *h, *p, *s, *q; int i, x;

    h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

    { s=(NODE *)malloc(sizeof(NODE)); s->data=rand(); s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h;}

    outlink(NODE *h, FILE *pf) { NODE *p; p = h->next;

    fprintf(pf ,\ while(p)

    { fprintf(pf ,\ fprintf (pf,\outresult(int s, FILE *pf)

    {fprintf(pf,\sum of even numbers: %d\\n\

    main(){ NODE *head; int even; head=creatlink(12); head->data=9000;

    outlink(head , stdout);

    14

    58.给定程序的功能是根据公式求P的值,结果由函数值m!带回。m与n为两个正整数且要求m>n。P?

    n!(m?n)!例如:m=11,n=4时,运行结果为330.000000。

    #include long jc(int m)

    { long s=1; int i ;

    /**************found**************/ for(i=1;i<=m;i++) s=___1___ ; return s;}

    float fun(int m, int n) { float p;

    /**************found**************/ p=1.0*jc(m)/jc(n)/jc(___2___) ; /**************found**************/ ___3___;}

    main(){ printf(\第一空:s*i 第二空:m-n 第三空:return p

    59.给定程序的功能是把a数组中的n个数,和b数组中

    逆序的n个数一一对应相乘求平方,结果存在c数组中。例如:当a数组中的值是:1、3、5、7、8,b数组中的值是:2、3、4、5、8,c中存放的数据是:64、225、400、441、256。

    #include

    void fun(int a[], int b[], int c[], int n) { int i;

    for (i=0; i

    /**************found**************/

    _1___ = (a[i] * b[n-1-i]) *(a[i] * b[n-1-i]);} main()

    { int i, a[100]={1,3,5,7,8}, b[100]={2,3,4,5,8}, c[100];

    /**************found**************/ fun(___2___, 5);

    printf(\

    /**************found**************/

    for (i=0; i<5; i++) printf(\ printf(\

    第一空:c[i] 第二空:a,b,c 第三空:c[i]

    60.给定程序的功能是根据公式计算S,计算结果通过形

    参指针sn传回;n通过形参传入。

    11111Sn???????例如,若n的值为15

    13572n?1时,输出结果是:S=0.769788 N=15。 #include

    void fun(float *sn, int n)

    {/**************found**************/ int i,j=___1___; float s=0.0;

    for(i=0;i<=n;i++) { s=s+j*1.0/(2*i+1); j*=-1; }

    /**************found**************/ ___2___=s;}

    main(){ int n=15; float s;

    /**************found**************/ fun(___3___);

    printf(\第一空:1 第二空:*sn 第三空:&s,n

    1 2 3 程序执行结果为 0 0 1 4 5 6 0 0 4 7 8 9 0 0 7 #include #define N 4

    void fun(int (*t)[N], int m) { int i, j;

    /**********found**********/ for(i=0; i=0; j--) /**********found**********/

    t[i][j+___2___ ]=t[i][j]; /**********found**********/ for(j=0; j<___3___; j++) t[i][j]=0; }} main()

    { int t[][N]={21,12,13,24,25,16,47,

    38,29,11,32,54,42,21,33,10}, i, j, m; printf(\ for(i=0; i

    printf(\ printf(\

    printf(\scanf(\ fun(t,m);

    printf(\ for(i=0; i

    printf(\ printf(\

    第一空:i++ 第二空:m 第三空:m

    61.给定程序的功能是把s 串中所有的字母改写该字母

    63.给定程序的功能是建立一个带有头结点的单向链

    表,并用随机函数为各结点赋值。函数fun的功能查找结点数据域最大值,并且作为函数值返回。 #include #include typedef struct aa

    { int data; struct aa *next; }NODE; int fun(NODE *h) { int max = 0 ;

    /***********found**********/ ___1___ *p; p=h->next;

    /***********found**********/ max=___2___ while(p)

    { if(p->data>max) max=p->data;

    /***********found**********/ ___3___ } return max;}

    NODE *creatlink(int n) { NODE *h, *p, *s, *q; int i, x;

    h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

    62.给定程序中,函数fun的功能是:有N×N矩阵,根 { s=(NODE *)malloc(sizeof(NODE)); 据给定的m(mdata=rand();

    s->next=p->next; 左边置为0。例如,N=3,m=2,则下列矩阵

    的下一个字母,字母z改写成字母a。大写字母仍为大写

    字母,小写字母仍为小写字母,其它字符不变。 #include #include #include #define N 81 fun ( char *s )

    {/**************found**************/ char *p = ___1___ ; while(*p) {

    /**************found**************/ if(*p == 'Z') *p = ___2___ ; /**************found**************/ else if(*p == 'z') *p = ___3___ ; else if(isalpha(*p)) *p = (*p) + 1 ; p++ ; }}

    main( ){ char a[N];

    printf ( \ printf ( \original string is : \); puts( a ); fun ( a );

    printf ( \ puts ( a );}

    第一空:s 第二空:’A’或65 第三空:’a’或97

    15

    p->next=s; p=p->next; } p->next=NULL; return h;}

    outlink(NODE *h, FILE *pf) { NODE *p; p = h->next;

    fprintf(pf ,\ while(p)

    { fprintf(pf ,\ fprintf (pf,\}

    outresult(int s, FILE *pf)

    {fprintf(pf,\main()

    { NODE *head; int even; head=creatlink(12); head->data=9000;

    outlink(head , stdout); even=fun(head);

    printf(\ outresult(even, stdout);}

    第一空:NODE 第二空:p->data 第三空:p=p->next

    ___2___; } for (i=0;i

    strcat(f,s); strcpy(ch,f); }

    printf(\

    第一空:(ch[i]==’o’) 第二空:i++ 第三空:break

    66. 给定程序的功能是:从键盘输入一个字符串(长度

    不超80个字符),依次扫描字符串的小写字母o,每次将小写字母o左侧所有小写字母转换为大写字母,大写字母转换为小写字母。并把小写字母o删除,依次直至小写字母o处理完,之后把已处理的字符串输出到屏幕。例如:输入字符串为”aA1BoCao”,处理后输出为”aA1BcA”。输入字符串”aAobC”,输出为”AabC”。 #include #include void main()

    {int i=0,j=0,nulin,sj=0,m; char ch[80];

    printf(\ scanf(\

    while (ch[i]!='\\0') { if (ch[i]=='o') sj++; i++; }

    for (i=0;i

    /***************found***************/ ___1___;

    for (m=0;m

    {if (ch[m]>='a' && ch[m]<='z') ch[m]=ch[m]-32;

    /***************found***************/ ___2___

    if (ch[m]>='A' && ch[m]<='Z') ch[m]=ch[m]+32; } if (m>=j)

    ch[m]=ch[m+1]; }

    /***************found***************/ ___3___;}

    printf(\

    第一空:nulin=strlen(ch); 第二空:else 第三空:ch[nulin-1]=’\\0’;

    64. 给定程序的功能是把一个字符串的字符复制到另

    外一个字符串中。

    void cpystr(char *ps,char *pd) { while(*ps!='\\0') { *pd=*ps; pd++;

    /******found******/ ___1___; } /******found******/ *pd=___2___;} main(){

    char *pa=\ pb=b;

    /******found******/ ___3___

    printf(\ return 0;}

    第一空:ps++ 第二空:’\\0’或0 第三空:strcpy(pa,pb);

    65. 给定程序的功能是:从键盘输入一个字符串(长度

    不超过80个字符),依次扫描字符串中的小写字母o,每次将小写字母o的左右字符串部分作交叉换位,即左边字符串移到小写字母o的右边,而原先右边的则返之。并把小写字母o删除,依次直至小写字母o处理完,之后已处理的字符串出到屏幕。例如:输入字符串为:”123oabco98”,处理后输出为”98123abc”。 void main()

    {int i=0,j=0,sj=0,bs; char ch[80]; char *s,*f;

    printf(\ scanf(\

    while (ch[i]!='\\0') { /******found******/ if ___1___ {sj++;}

    /******found******/

    16

    67. 给定函数

    countValue(int n),它的功能是:求n

    以内(不包括n)同时被3与7整除的所有自然数之和的平方根s,s作为函数返回值。主程序调用该函数输出n为1000时的函数值153.909064。 /******found******/

    ___1___ countValue(int n)

    { double xy=0.0; int i;

    /******found******/ for(i=8;__2___;i++)

    if(i%3==0&&i%7==0) xy+=i; xy=sqrt((double)xy); /******found******/ ___3___;} main()

    { printf(\第一空:double 第二空:i

    68. 给定函数

    countValue(int n),它的功能是:求n

    以内(不包括包括n)同时能被7与11整除的所有自然数的平方根之和s,s作为函数返回值。主程序调用该函数输出n为1000时的函数值。 double countValue(int n) /******found******/ { ___1___xy=0.0; int i;

    for(i=1;i

    if(i==0&&i%7==0) /******found******/ ___2___; return xy;} main(){

    /******found******/

    printf(\

    第一空:double 第二空:xy=xy+sqrt((double)i) 第三空:countValue(1000)

    ┌1 (n=0,1) n!= ┤

    └n×(n-1)!(n>1) #include long ref(int n) { long m;

    if (n<0) printf(\/************found************/ else if (___1___) m=1;

    /************found************/ else ___2___; return(m);}

    main(){ int n; long y;

    printf(\/************found************/ scanf(\ y=ref(n);

    printf(\ return;} 第一空:(n==0||n==1)第二空:m=ref(n-1)*n 第三空:&n

    71.给定程序的功能是求出数组中的最大数max及最大

    数的个数cnt数组xx中值能被3整除或能被7整除的算术平均值pj(保留职位小数),结果max,cnt,pj输出到屏幕。

    #define N 20 void main() { int max;

    int cnt,xx[N]={78,43,56,34,43,32,85, 43,46,10,90,34,90,3,52,61,42,89,90,54}; float pj;

    long j=0; int I,k;

    /*************found************/ ___1___

    /*************found************/ for(___2___;I

    /*************found************/ {if (xx[I]>max) ___3___;

    if (xx[I]%3==0||xx[I]%7==0) {j+=xx[I];k++;} } for (I=0,cnt=0;I

    printf(\max,cnt,pj);}

    第一空:max=xx[0];第二空: for(i=0,k=0;i

    69. 给定程序的功能分别求

    7个学生三门课程的平均

    成绩,在主程序中输出各学生平均成绩和最大平均成绩av。

    float fun(float a,float b,float c) { float sum,aver; sum=a+b+c;

    /**********found************/ ___1___; return(aver);}

    main(){ float a[7][3]={{80,90.5,81.5}, {70,69.8,90.5}, {68,97,99.0}, {86.5,89,95}, {78,96,90}, {87.5,89,92}, {64.5,80,78}}; float av=0.0,b[7];int i; for (i=0;i<7;i++)

    /**********found************/ {b[i]=___2___;

    /**********found************/ if ___3___ av=b[i];} for (i=0;i<7;i++)

    printf(\ printf(\

    第一空:aver=sum/3.0 第二空:b[i]=fun(a[i][0],a[i][1],a[i][2]); 第三空:if(av

    70.给定程序的功能是用递归法计算n!。用递归方法计算n!,可使用如下公式表示

    17

    72. 给定程序的功能是找出所有100以内(含100)满

    足I,I+4,I+10都是素数的整数I(I+10也以100以内)的个数cnt以及这些I之和sum。 int cnt,sum;

    int isPrime(int number) { int i,tag=1;

    if(number==1) return 0;

    for(i=2;tag&&i<=number/2;i++)

    /***************found***************/ if(___1___) tag=0; return tag;} void countValue()

    { int I,count=0,xx[30];

    int j,k,m; cnt=0; sum=0;

    /***************found***************/ for(I=1;___2___;I++)

    if(isPrime(I)) {xx[count]=I;count++;} for(I=0;I

    if (isPrime(xx[I]+4)&&isPrime(xx[I]+10)) /***************found***************/ {___3___;}}

    void main(){ cnt=sum=0;

    countValue();printf(\printf(\

    第一空:number%i==0 第二空:I<90 第三空:cnt++;sum+=xx[I]

    75. 给定程序的功能是计算学生和平均成绩和不及格

    的人数。

    struct stu_list { int num;

    char name[20]; char sex; float score;

    }s[5]={{9801,\

    {9802,\ {9803,\ {9804,\ {9805,\main()

    { int i,c=0;

    float ave,sum=0; for (i=0;i<5;i++) {

    /***************found***************/ sum+=___1___;

    /***************found***************/ if (___2___) c+=1;} printf(\

    /***************found***************/ ___3___;

    printf(\ return; }

    第一空:sum+=s[i].score 第二空:if(s[i].score<60) c+=1 第三空:ave=sum/5;

    73.给定程序的功能是对从键盘输入的字符数组

    xx(不

    超过80个字符),按字符从大到小的顺序进行排序,排序后的结果存入字符串数组xx中。例如:输入:dAe,BfC.结果:fedCBA.

    #include void main()

    { char xx[80] ; int numi,numj; char ch;

    printf(\ scanf(\

    for (numi=0;numi

    /***************found***************/ for (numj=___1___;numj

    /***************found***************/

    ___2___;

    xx[numi]=xx[numj];

    /***************found***************/

    ___3___;}

    printf(\

    第一空:numi+1 第二空:ch=xx[numi] 第三空:xx[numj]=ch

    76. 给定程序的功能是在三位整数(100至999)中寻

    找符合下面条件的整数,并依次从小到大存入数组b[]中;它既是完全平方数,又有两位数相同,例如144,676等。函数int jsValue(int n)判断参数是否满足该条件,如果满足该条件函数返回值为1,否则返回值为0。 #include int jsValue(int n) { int j,k=0;

    int n1,n2,n3; j=10; while(j*j<=n)

    74. 给定程序的功能是:对字符数组xx中字符按给定 { if (n==j*j) 的替代关系对所有字符进行替代,仍存入数组xx的对应 { n1=n / 100;

    的位置上。替代关系:f(p)=p*11 mod 256(p是数组xx/***************found***************/ 中某一个字符的ASCII值,f(p)是计算后新字符的ASCII n2=___1___; 值),如果原字符是大写字母或计算后f(p)值小于等于 n3=n % 10; 32, 则该字符不变,否则将f(p)所对应的字符进行替代。 if(n1==n2||n1==n3||n2==n3) void main() k=1; } { char xx[80]; /***************found***************/ int i,j; ___2___; } printf(\ return k;} scanf(\main() /***************found***************/ { int b[20],num,i; for (i=0;___1___;i++) for (i=100,num=0;i<=999;i++) if((('A'<=xx[i])&&(xx[i]<='Z'))|| if (jsValue(i)==1) (((xx[i]*11) % 256 )<=32)) { b[num]=i; /***************found***************/ /***************found***************/ ___2___ ___3___; } else for (i=0;i

    元素,然后输出对角线元素之和。

    18

    int fun()

    { int a[3][3],sum; int i,j;

    /***************found**************/ sum=___1___;

    for (i=0;i<3;i++) {for (j=0;j<3;j++)

    /***************found**************/

    scanf(\ for (i=0;i<3;i++)

    /***************found**************/ ___3___

    printf(\main(){ fun();}

    第一空:sum=0 第二空:& 第三空:sum=sum+a[i][i];

    78. 给定程序的功能是求下列分数序列的前n项之和。

    n值从键盘输入,和值通过函数值返回主程序输入。

    { int i,j,k; USER temp;

    for(i=0;i

    for(j=i+1;j

    if (strcmp(sp[k].name,sp[j].name)>0) k=j; temp=sp[k];sp[k]=sp[i];sp[i]=temp; }} outdata(USER *sp) { int i;

    printf(\ for (i=0;i

    printf(\main(){ USER sp[N],temp; getdata(sp); getsort(sp); outdata(sp);}

    第一空:USER *sp 第二空:gets 第三空:gets

    码,按姓名的字典顺序排列后,输出用户的姓名和电话号码。函数getdata读入五位用户的姓名和电话号码。

    8.391667。 getsort函数把数据按姓名的字典顺序排序。outdata输double fun(int n) 出最后的结果。 { int a,b,c,k; double s; #define N 5 s=0.0; a=2; typedef struct /***************found***************/ { char name[20]; ___1___; char num[10]; for (k=1;k<=n;k++) }USER; { s=s+(double)a/b; getdata(USER *sp) c=a; a=a+b;b=c; } { int i; /***************found***************/ printf(\ ___2___;} for(i=0;i

    printf(\function is: %lf\\n\/***************found***************/ fun(n));} ___1___; 第一空:b=1第二空:return s 第三空:&n for(i=0;i

    for(j=i+1;j

    码,按姓名的字典顺序排列后,输出用户的姓名和电话

    if (strcmp(sp[k].name,sp[j].name)>0) k=j;

    号码。函数getdata读入五位用户的姓名和电话号码。

    temp=sp[k];

    getsort函数把数据按姓名的字典顺序排序。outdata输

    /***************found***************/

    出最后的结果。

    ___2___;

    #define N 5

    /***************found***************/

    typedef struct

    ___3___; }}

    { char name[20];

    outdata(USER *sp)

    char num[10];

    { int i; printf(\

    }USER;

    for (i=0;i

    /***************found***************/

    printf(\

    getdata(___1___)

    main(){ USER sp[N],temp;

    { int i;

    getdata(sp);

    printf(\

    getsort(sp);

    for(i=0;i

    outdata(sp);}

    {printf(\

    第一空:USER temp 第二空:sp[k]=sp[i]; 第三空:

    /***************found***************/

    sp[i]=temp;

    printf(\/***************found***************/ 81.给定程序的功能是找出方阵中每列最小元素以及所 printf(\在的行号。函数findmin找出每列中最小元素所在行号,getsort (USER *sp) 函数outdata输出方阵中每列最小元素及其所在行号。

    19

    23581321,,,,,,??例如:若n=5,则应该输出:123581880. 给定程序的功能是读入五位用户的姓名和电话号

    #define M 4 main()

    { int s[M][M]={{14,23,52,3},

    {34,22,52,41},{12,15,8,9},{54,98,23,21}}; int im[M]; findmin(s,im);

    outdata(s,im);}

    findmin(int a[][M],int ln[]) { int i,j,t;

    for (i=0;i

    /***************found***************/ for(j=1;___1___;j++)

    if(a[j][i]

    /***************found***************/ ___2___; }}

    outdata(int(*a)[M],int *ln) { int i,j;

    printf(\ for(i=0;i

    { for (j=0;j

    printf(\ printf(\

    printf(\ for (i=0;i

    /***************found***************/ printf(\ printf(\

    第一空:j

    printf(\ for (i=0;i

    /***************found***************/ {printf(\ sum=sum+ a[i][ln[i]]; } printf(\

    第一空:t=j;第二空:sum=0; 第三空:ln[i]

    main函数读入数组a的各元素

    值,inver函数逆序后重新放置数组a元素的值。 #define N 10

    void invert(int *s,int i,int j) { int t; if (i

    /***************found***************/ *(s+i)=___1___; *(s+j)=t;

    /***************found***************/ invert(s,___2___,j-1); }} main()

    { int a[N],i;

    for (i=0;i

    { printf(\

    /***************found***************/ scanf(\ invert(a,0,N-1); for (i=0;i

    printf(\ printf(\

    82. 定程序的功能是找出方阵中每行最大元素以及所} 在的列号。函数finemax找出每行中最大元素所在列号,第一空:s[j] 第二空:i+1 第三空:a+i 函数outdata输出方阵中每最行大元素及其所在行号和

    84. 定程序的功能是:将无符号八进制数字构成的字符每行中最大元素的和sum。

    串转换为十进制整数。例如,输入的字符串为:556,则#define M 4

    输入十进制整数366。 main()

    main() { int s[M][M]={{14,23,52,3},

    /***************found***************/ {34,22,52,41},

    { char ___1___,s[6]; {12,15,8,9},

    int n; p=s; gets(p); {54,98,23,21}};

    /***************found***************/ int im[M],sum;

    n=___2___; findmax(s,im);

    /***************found***************/ outdata(s,im);}

    while(___3__!='\\0') findmax(int a[][M],int ln[])

    n=n*8+*p-'0'; printf(\ { int i,j,t;

    第一空:*p 第二空:*p-‘0’ 第三空:*(++p) for (i=0;i

    { t=0; 85. 定函数int MySearch(char *str,char *s)的功能 for(j=1;ja[i][t]) 若输入字符串”12 123 12345”和”23”,则应输出2(表/***************found***************/ 示字符串”23”在字符串”12 123 12345”中出现了两 ___1___; 次)。若输入字符串”33333”和”33”,则应输出4(表 ln[i]=t; }} 示字符串”33”在字符串”33333”出现了四次)。 outdata(int(*a)[M],int *ln) int MySearch( char* str, char* s ) { int i,j,sum; { char* p; printf(\ int n =0; /***************found***************/ for( ; *str; ) ___2___; /***************found***************/ for(i=0;i

    20

    83. 定程序和功能是

    int fun(char *fname ) if(p.num[0]==0) { FILE *fp; int i,n; float x; printf(\ if((fp=fopen(fname, \ else for(i=1;i<=10;i++) { printf(\/**********found**********/ printf(\ %d-%d-%d\\n\fprintf(___1___,\ } printf(\!\\n\} /**********found**********/

    1.给定程序中,函数fun的功能是:求出形参ss所指 ___2___;

    字符串数组中最长字符串的长度,其余字符串左边用字 printf(\

    /**********found**********/ 符*补齐,使其与最长的字符串等长。字符串数组中共有 if((fp=fopen(___3___,\M个字符串,且串长

    #define M 5

    { printf(\%f\\n\#define N 20 fscanf(fp,\

    void fun(char (*ss)[N]) fclose(fp);

    { int i, j, k=0, n, m, len; return 1;

    } for(i=0; i

    if(len>n) {

    }

    /**********found**********/

    n=len; ___1___=i;} } //kk 第一空:fp 第二空:fclose(fp) 第三空:fname

    for(i=0; i

    if (i!=k) { m=n;

    112.人员的记录由编号和出生年、月、日组成,N名 len=strlen(ss[i]); 人员的数据已在主函数中存入结构体数组std中,且编

    号唯一。函数fun的功能是:找出指定编号人员的数据,/**********found**********/

    作为函数返回值,由主函数输出,若指定编号不存在, for(j=___2___; j>=0; j--) //len

    ss[i][m--]=ss[i][j]; 返回数据中的编号为空串。

    #define N 8 for(j=0; j

    main(){char ss[M][N]={\/**********found**********/

    \___1___fun(STU*std,char*num) //STU cchongqing\

    printf(\{ int i; STU a={\

    for (i=0; i

    for(i=0; i

    return (___3___); //std[i]

    printf(\ return a;

    }

    main() { STU std[N]={ {\1},{\

    {\66\

    {\ STU p; char n[10]=\ p=fun(std,n);

    26

    2. 给定程序中,函数fun的功能是:求ss所指字符串数组中长度最长的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指变量中。ss所指字符串数组中共有M个字符串,且串长

    /**********found**********/ int fun(char (*ss) ___1___, int *n) //[N] { int i, k=0, len=0; for(i=0; i

    /**********found**********/

    if(i==0) *n=___2___; //len if(len>*n) {

    /**********found**********/

    ___3___; //*n=len k=i; } } return(k);} main()

    { char ss[M][N]={\\cchongqing\

    printf(\ for(i=0;i

    printf(\leng longest string is : %d\\n\printf(\3.函数fun的功能是:把形参a所指数组中最大值放在a[0]中,接着求出a所指数组中最小值放在a[1]中;再把a所指数组元素中的次大值放在a[2]中,把a数组元素中次小值放在a[3]中;其余依次类推。例如:若a所指数组中的数组最初排列为:1、4、2、3、9、6、5、8、7,则按规则移动后,数据排列为:9、1、8、2、7、3、6、4、5.形参n中存放a所指数组中数据的个数。 #define N 9

    /**********found**********/

    void fun(int ___1___, int n) //*a { int i, j, max, min, px, pn, t; /**********found**********/

    for (i=0; i

    /**********found**********/

    for (j=___3___; j

    { max = a[j]; px = j; } if (min > a[j])

    { min = a[j]; pn = j; }} if (px != i)

    { t = a[i]; a[i] = max;

    a[px] = t;

    if (pn == i) pn= px; }

    if (pn != i+1)

    { t = a[i+1]; a[i+1] = min; a[pn] = t; }}} main()

    { int b[N]={1,4,2,3,9,6,5,8,7}, i; printf(\

    for (i=0; i

    printf(\for (i=0; i

    4. (7)给定程序的功能是:调用函数fun将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制过程中,把复制的内容

    27

    输出到终端屏幕.主函数中源文件中入在变量sfname k ,目标文件名放在变量tfname中。

    int fun(char *source, char *target) { FILE *fs,*ft; char ch; /**********found**********/

    if((fs=fopen(source, ___1___))==NULL) //”r’ return 0;

    if((ft=fopen(target, \ return 0;

    printf(\ ch=fgetc(fs);

    /**********found**********/

    while(!feof(___2___)) // fs { putchar( ch );

    /**********found**********/

    fputc(ch,___3___); //ft ch=fgetc(fs); } fclose(fs); fclose(ft); printf(\

    main(){char sfname[20] =\tfname[20]=\

    FILE *myf; int i; char c; myf=fopen(sfname,\

    printf(\ for(i=1; i<30; i++)

    {c='A'+rand()%;fprintf(myf,\printf(\

    fclose(myf);printf(\ if (fun(sfname, tfname))

    printf(\ else printf(\

    5. 用筛选法可得到2~n(n<10000)之间的所有素数,方法是:首先从素数2开始,将所有2的倍数的数从数表中删去(把数表中相应位置的值置成0);接着从数表中找下一个非0数,并从数表中删去该数的所表倍数;依次类推,直到所找的下一个数等于n为止。这样会得一个序列:2,3,5,7,11,13,17,19,23??函数fun用筛选法找出所有小于等于n的素数,并统计素数的个数作为函数值返回。

    int fun(int n)

    { int a[10000], i,j, count=0; for (i=2; i<=n; i++) a[i] = i; i = 2; while (i

    for (j=a[i]*2; j<=n; j+=___1___) a[j] = 0; i++; /**********found**********/ while (___2___==0) i++; }

    printf(\ for (i=2; i<=n; i++) /**********found**********/ if (a[i]!=___3___)

    {count++;

    printf( count?\ return count;}

    main(){ int n=20, r;r = fun(n);

    printf(\第一空:a[i] 第二空:a[i] 第三空0

    6.函数fun的功能是:从三个形参a,b,c中找出中间的那个数,作为函数值返回。例如:当a=3,b=5,c=4时,中数为4。

    int fun(int a, int b, int c) { int t;

    /**********found**********/

    t = (a>b) ? (b>c? b :(a>c?c:___1___)) : ((a>c)?___2___ : ((b>c)?c:___3___)); return t;}

    main(){ int a1=3, a2=5, a3=4, r; r = fun(a1, a2, a3);

    printf(\第一空:a 第二空:a 第三空:b 7. 函数fun的功能是:计算

    x2xnf(x)?1?x????

    2!n!xn?10?6。若x=2.5,函数值为:12.182494。 直到n!double fun(double x) { double f, t; int n; /**********found**********/ f = 1.0+___1___; t = x; n = 1; do {

    n++;

    /**********found**********/ t *= x/___2___; /**********found**********/ f += ___3___;

    } while (fabs(t) >= 1e-6); return f;}

    main(){ double x, y; x=2.5; y = fun(x);

    printf(\

    printf(\第一空:x 第二空:n 第三空:t

    8. 给定程序中,函数fun的功能是:对形参ss所指字符串数组中的M个字符串按长度由短到长进行排序。ss所指字符串数组中共有M个字符串,且串长

    void fun(char (*ss)[N])

    { int i, j, k, n[M]; char t[N]; for(i=0; i

    28

    for(i=0; i

    /**********found**********/ for(j=___1___; jn[j]) ___2___; if(k!=i)

    { strcpy(t,ss[i]); strcpy(ss[i],ss[k]); /**********found**********/ strcpy(ss[k],___3___); n[k]=n[i]; } }} main()

    { char ss[M][N]={\\ int i;

    printf(\ for(i=0; i

    printf(\ for(i=0; i

    第一空:i+1 第二空:k=j 第三空:t

    9. 函数fun的功能是:把形参a所指数组中的最小值放在元素a[0]中,接着把形参a所指数组中的最大值放在a[1]元素中;再把a所指数组元素中的次小值放在a[2]中,把a所指数组元素中的次大值放在a[3];其余以此类推。例如:若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7;则按规则移动后,数据排列为:1、9、2、8、3、7、4、6、5。形参n中存放a所指数组中数据的个数。

    #define N 9

    void fun(int a[], int n)

    { int i,j, max, min, px, pn, t; for (i=0; i

    {/**********found**********/ max = min = ___1___; px = pn = i;

    for (j=i+1; j

    { max = a[j]; px = j; } /**********found**********/ if (min>___3___)

    { min = a[j]; pn = j; } } if (pn != i)

    { t = a[i]; a[i] = min; a[pn] = t; if (px == i) px =pn; } if (px != i+1)

    { t = a[i+1]; a[i+1] = max; a[px] = t; } }}

    main()

    { int b[N]={9,1,4,2,3,6,5,8,7}, i; printf(\

    for (i=0; i

    printf(\ for (i=0; i

    第一空:a[i] 第二空:a[j] 第三空:a[j]

    10. 给定程序中,函数fun的功能是:将形参std所指结构体数组中年龄最大者的数据作为函数值返回,并在main函数中输出。 typedef struct { char name[10]; int age; }STD;

    STD fun(STD std[], int n) { STD max; int i; /**********found**********/ max= ___1___;

    for(i=1; i

    /**********found**********/

    if(max.age<___2___) max=std[i]; return max;} main( )

    { STD std[5]={\

    \ STD max; max=fun(std,5); printf(\/**********found**********/

    printf(\ ___3___,max.age);}

    第一空:*std 第二空:std[i].age 第三空:max.name 11.给定程序中,函数fun的功能是:将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。例如,形参s所指的字符串为:def35adh3kjsdf7。执行结果为:defadhkjsdf3537。 void fun(char *s) { int i, j=0, k=0; char t1[80], t2[80]; for(i=0; s[i]!='\\0'; i++) if(s[i]>='0' && s[i]<='9'){ /**********found**********/

    t2[j]=s[i]; ___1___; } else t1[k++]=s[i]; t2[j]=0; t1[k]=0;

    /**********found**********/ for(i=0; i

    for(i=0; i<___3___; i++) s[k+i]=t2[i];} main()

    29

    { char s[80]=\ printf(\ fun(s);

    printf(\第一空:j++; 第二空:s[i]=t1[i];第三空:j 12. 函数fun的功能是:把形参a所指数组中的奇数原顺序依次放到a[0]、a[1]、a[2]、??中,把偶数从数组中删除,奇数个数通过函数值返回。例如:若a所指数组中数据最初排列为:9、1、4、2、3、6、5、8、7,删除偶数后a所指数组中数据为:9、1、3、5、7,返回值为5。

    #define N 9

    int fun(int a[], int n) { int i,j; j = 0;

    for (i=0; i

    /**********found**********/ if (a[i]%2==___1___){ /**********found**********/ a[j] = a[i]; ___2___; } /**********found**********/ return ___3___;} main()

    { int b[N]={9,1,4,2,3,6,5,8,7}, i, n; printf(\ for (i=0; i

    printf(\ printf(\ for (i=0; i

    printf(\第一空:1 第二空:j++ 第三空j

    13. 给定程序中,函数fun的功能是:对形参s所指字符串下标为奇数的字符按ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参p所指字符数组中,形成一个新串。例如,形参s所指的字符串为:baawrskjghzlicda,执行后p所指字符数组中的字符串应为:aachjlsw。

    void fun(char *s, char *p) { int i, j, n, x, t; n=0;

    for(i=0; s[i]!='\\0'; i++) n++; for(i=1; i

    /**********found**********/

    for(j=___2___+2 ; js[j]) t=j; if(t!=i)

    { x=s[i]; s[i]=s[t]; s[t]=x; }}

    for(i=1,j=0; i

    /**********found**********/ p[j]=___3___;} main()

    { char s[80]=\ printf(\ fun(s,p);

    printf(\第一空:t=i 第二空:i 第三空 0

    14. 给定函数int MySearch(char *str,char *s)的功能是:统计字符串s在字符串str中出现的次数。例如,若输入字符串”12 123 12345”和”23”,则应输出2(表示字符串”23”在字符串”12 123 12345”中出现了两次)。若输入字符串”33333”和”33”,则应输出4(表示字符串”33”在字符串”33333”出现了四次)。 int MySearch( char* str, char* s ){ char* p; int n =0;

    for( ; *str; )

    /***************found***************/

    if( ( p = strstr( str, s ) ) != ___1___ ) { n++; str=p+1; } else

    /***************found***************/ ___2___;

    /***************found***************/ return( ___3___ );} main()

    { char str1[81], str2[21];

    printf(\ gets(str1);

    printf(\ gets(str2);

    printf( \times\\n\第一空:NULL 第二空:*str=0 第三空:n

    char string[81], x; clrscr();

    printf(\ gets(string);

    printf(\ scanf(\

    printf( \deleting %d '%c'(s), the string becomes:\\n%s\\n\x), x, string);}

    第一空:j++ 第二空:0 第三空:k

    16. 给定程序中已建立一个带有头结点的单向链表,链表中的各结点按结点数据域中的数据从小到大顺序链接。函数fun的功能是:把形参x的值放入一个新结点并插入到链表中,插入后各结点仍保持从小到大顺序排序。 #define N 8 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 && x>p->data) { /**********found**********/ q=___2___; p=p->next; } s->next=p;

    /**********found**********/ q->next=___3___;}

    SLIST *creatlist(int *a)

    { SLIST *h,*p,*q; int i;

    h=p=(SLIST *)malloc(sizeof(SLIST));

    15. 给定函数 char *MyDelete(char *str,char c)的功

    for(i=0; i

    能是:在字符串str中删除变量c中的字符,有几个删几

    { q=(SLIST *)malloc(sizeof(SLIST));

    个,并返回所删字符的个数。例如,若输入字符串”ab abc

    q->data=a[i]; p->next=q; p=q;

    bcdef”和字符’b’,则应输出字符串”a ac cdef”和

    }

    3(表示删了3个字符’b’)。

    p->next=0;

    int MyDelete( char* str, char c )

    return h;}

    { int i, j=0, k=0;

    void outlist(SLIST *h)

    for( i = 0; str[i]; i++ )

    { SLIST *p;

    if( str[i] != c )

    p=h->next;

    /***************found**************/

    if (p==NULL)

    { str[ j ]= str[i]; ___1___; }

    printf(\

    else

    else

    k++;

    { printf(\

    /***************found**************/

    do{printf(\

    str[j]=___2___ ;

    while(p!=NULL);

    /***************found**************/

    printf(\

    return( ___3___ );}

    main()

    main(){

    30

    { SLIST *head; int x;

    int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a);

    printf(\

    outlist(head);

    printf(\

    scanf(\ fun(head,x);

    printf(\ outlist(head);}

    第一空:x 第二空:p 第三空:s

    17. (4)给定程序的功能是:调用函数fun将指定源文件中的内容复制到指定的目标文件中,复制成功时函数返回值为1,失败时返回值为0。在复制过程中,把复制的内容输出到终端屏幕。主函数中源文件名放在变量sfname中,目标文件名放在变量tfname中。

    int fun(char *source, char *target) { FILE *fs,*ft; char ch; /**********found**********/

    if((fs=fopen(source, ___1___))==NULL) return 0;

    if((ft=fopen(target, \ return 0;

    printf(\ ch=fgetc(fs);

    /**********found**********/ while(!feof(___2___)) { putchar( ch );

    /**********found**********/ fputc(ch,___3___); ch=fgetc(fs); } fclose(fs); fclose(ft); printf(\ return 1;} main()

    { char sfname[20] =\

    tfname[20]=\

    FILE *myf; int i; char c; myf=fopen(sfname,\

    printf(\ for(i=1; i<30; i++)

    {c='A'+rand()%;fprintf(myf,\printf(\

    fclose(myf);printf(\ if (fun(sfname, tfname)) printf(\ else printf(\

    第一空: “r” 第二空:fs 第三空:ft

    18. 给定程序中,函数fun的功能是:读自然数1~10以及它们的平方根写到名为myfile3.txt的文本文件中,然后再顺序读出显示在屏幕上。 int fun(char *fname )

    31

    { 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实现。

    void WriteText(FILE *); void ReadText(FILE *); main()

    {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

    for (j = i + 1; j < 6; j++) { /**************found**************/ if(strcmp(*(pstr+i),___1___)>0) { p = *(pstr + i) ;

    20. 给定程序的功能是:调用fun函数建立班级通讯录。

    /**************found**************/

    通讯录中记录每个学生的编号、姓名和电话号码。班级

    pstr[i] = ___2___ ;

    的人数和学生的信息从键盘读入,每个人的信息作为一

    /**************found**************/

    个数据块写到myfile5.dbf的二进制文件中。

    *(pstr + j) = ___3___ ; }} }}

    #define N 5

    main( )

    typedef struct

    { int i ;

    { int num;

    char *pstr[6], str[6][MAXLINE] ;

    char name[10];

    for(i = 0; i < 6 ; i++) pstr[i] = str[i] ;

    char tel[10];

    printf( \) ;

    }STYPE;

    for(i = 0 ; i < 6 ; i++)

    void check();

    scanf(\

    /**********found**********/

    fun(pstr) ;

    int fun(___1___ *std){

    printf(\

    /**********found**********/

    for(i = 0 ; i < 6 ; i++)

    ___2___ *fp; int i;

    printf(\

    if((fp=fopen(\

    第一空:*(pstr+j)或pstr[j]

    return(0);

    第二空:*(pstr+j)或pstr[j]

    printf(\

    第三空:p

    for(i=0; i

    /**********found**********/ 22.给定程序的功能是将十进制整数m转换成k进制fwrite(&std[i], sizeof(STYPE), 1, ___3___); (2≤k≤9)数的数字输出。例如,如果输入8和2,则 fclose(fp); return (1);} 应该输出1000。 main() #include { STYPE s[10]={ {1,\void fun( int m, int k ) {2,\{ int aa[20], i; for( i = 0; m; i++ ) { {4,\/**********found**********/ int k; aa[i] = ___1___; k=fun(s); /**********found**********/ if (k==1) m /= ___2___; } { printf(\ for( ; i; i-- ) else printf(\/**********found**********/ void check() printf( \{ FILE *fp; int i; STYPE s[10]; main(){ int b, n; if((fp=fopen(\printf( \ { printf(\ scanf( \ printf(\ fun( n, b );} printf(\第一空;m%k 第二空:k 第三空:aa for(i=0; i

    23.给定程序的功能是将未在字符串s中出现、而在字符

    { fread(&s[i],sizeof(STYPE),1, fp);

    串t中出现的字符,形成一个新的字符串放在u中,u

    printf(\

    中字符按原字符串中字符顺序排列,但是去掉重复字符。

    s[i].num,s[i].name,s[i].tel); }

    例如:当s=”12345”,t=”24677”,u中的字符为”67”

    fclose(fp);}

    #include

    第一空:STYPE 第二空:FILE 第三空:fp

    #include

    21. 给定程序的功能是用冒泡法对6个字符进行排序 void fun (char *s, char *t, char *u) #include { int i, j, sl, tl, k, ul=0; #define MAXLINE 20 sl = strlen(s); tl = strlen(t); fun ( char *pstr[6]) for (i=0; i

    32

    if (j>=sl)

    { for (k=0; k

    if (t[i] == u[k]) ___1___ ; if (k>=ul)

    /************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 #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 #include

    33

    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 #include char fun(char c)

    { 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

    #include float f( double x){

    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 float fun ( float r )

    {/**********found**********/

    return 3.14159 * ___1___ /2.0;} main ( )

    /**********found**********/ { ___2___ x;

    printf ( \/**********found**********/ scanf ( \

    printf (\第一空:r*r 第二空:float 第三空:&x

    29.给定程序的功能是将既在字符串s中出现、又在字符串t中出现的字符形成一个新字符串放在u中,u中字符按原字符串中字符顺序排列,但去掉重复字符。例如:当s=”42562”,t=”34”,u中的字符串为:”5”。 #include #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

    if (s[i] == t[j]) break; if(j

    { for (k=0; k

    if (s[i] _1_ u[k]) break; if (k>=ul)

    /************found************/ u[ul++]=___2___ ; }} /************found************/

    34

    ___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 #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 #include

    void fun (char *s, char *t, char *u) { int i, j, sl, tl;

    sl = strlen(s); tl = strlen(t); for (i=0; i

    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 #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

    if (s[i] == t[j]) ___1___ ; /************found************/ if(j ___2___ tl) *u++ = s[i]; } *u = '\\0';

    ul = strlen(up);

    for (i=0; i

      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的值通过形参传入

      35

      S?N??234N?1?????例如:若q的值为50.0,123N则函数值为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 long fun ( int k)

      {/************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 IsPrime ( int n )

      { 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( \2 and 10000: \

      /************found************/ scanf( \

      printf( \prime factor(s) of %d is( are ):\k ); 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( \第一空: (*a)++ 第二空:(*b)++ 第三空:upper,lower

      #define M 10

      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 (\

      /**************found**************/ fun ( ___2___ ) ;

      for ( i = 0 ; i < n ; i++) { for (j = 0 ; j < n ; j++) /**************found**************/ printf ( \ printf ( \

      第一空:a[j][k] 第二空:a,n 第三空:a[i][j]

      39.给定程序的功能是对a数组中n个人员的工资进行分段统计,各段的人数存到b数组中;工资为1000元以下的人数存到b[0]中, 工资为1000元到1999元的人数存到b[1]中, 工资为2000元到2999元的人数存到b[2], 工资为3000元到3999元的人数存到b[3], 工资为4000

      37.给定程序的功能是判断字符ch是否与串str中的某

      元到4999元的人数存到b[4],工资为5000元以上的人数

      个字符相同;若相同,什么也不做,若不同,则插在串的最

      存到b[5]中。例如,当a数组中的数据为:900、1800、

      后。

      2700、3800、5900、3300、2400、7500、3800,调用该

      #include

      函数后,b中存放的数据应是:1、1、2、3、0、2

      #include

      #include

      void fun(char *str, char ch )

      void fun(int a[], int b[], int n)

      { while ( *str && *str != ch ) str++;

      { int i;

      /**********found**********/

      /**************found**************/

      if ( *str ___1___ ch )

      for (i=0; i<6; i++) b[i] = ___1___;

      { str [ 0 ] = ch;

      for (i=0; i

      /**********found**********/

      if (a[i] >= 5000) b[5]++;

      ___2___ = 0; }}

      /**************found*************/

      main( ){ char s[81], c ;

      ___2___ b[a[i]/1000]++;}

      printf( \enter a string:\\n\); gets ( s );

      main()

      printf (\

      { int i, a[100]={ 900, 1800, 2700, 3800, 5900, 3300,

      c = getchar();

      2400, 7500, 3800}, b[6];

      /**********found**********/

      fun(a, b, 9);

      fun(___3___) ;

      printf(\

      printf( \

      /**************found**************/

      第一空:!= 第二空:*(str+1)或*(++str)

      for (i=0; i<6; i++)

      第三空: s,c

      printf(\

      38.给定程序的功能是根据形参m(2≤m≤9),在二维数组 printf(\中存放一张m行m列的表格,由main()函数输出。例如:第一空:0 第二空:else 第三空:b[i] 若输入 3

      40.给定程序的功能是将n个人员的考试成绩进行分段统

      则输出: 1 2 3

      计,考试成绩放在a数组中,各分数段的人数存到b数

      2 4 6

      组中:成绩为60到69的人数存到b[0], 成绩为70到

      3 6 9

      79的人数存到b[1], 成绩为80到89的人数存到b[2],

      #include

      成绩为90到99的人数存到b[3],成绩为100的人数存到

      36

      b[4],成绩为60分以下的人数存到b[5]中。例如,当a数组中的数据是:93、85、77、68、59、43、94、75、98。调用该函数后,b数组中存放的数据应是:1、2、1、3、0、2。

      #include

      void fun(int a[], int b[], int n) { int i;

      for (i=0; i<6; i++) b[i] = 0; /**************found**************/ for (i=0; i< ___1___; i++) if (a[i] < 60) b[5]++;

      /**************found**************/ ___2___ b[(a[i]- 60)/10]++;} main()

      { int i, a[100]={ 93, 85, 77, 68, 59, 43, 94, 75, 98}, b[6];

      /**************found**************/ fun(___3___, 9);

      printf(\

      for (i=0; i<6; i++) printf(\ printf(\

      第一空:n 第二空:else 第三空:a,b

      void fun( SLIST *p) { SLIST *t, *s; t=p->next; s=p; while(t->next != NULL) { s=t;

      /**********found**********/ t=t->___1___; } /**********found**********/ printf(\ s->next=NULL;

      /**********found**********/ free(___3___);}

      SLIST *creatlist(int *a)

      { SLIST *h,*p,*q; int i;

      h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i

      { q=(SLIST *)malloc(sizeof(SLIST)); q->data=a[i]; p->next=q; p=q;} p->next=0; return h;}

      void outlist(SLIST *h) { SLIST *p; p=h->next;

      41.给定程序的功能是求出1到1000之内能被7或11整

      if (p==NULL) printf(\

      除但不能同时被7和11整除的所有整数放存数组a中,

      else

      通过n返回这些数的个数。

      { printf(\

      #include

      do{printf(\ p=p->next; }

      void fun(int *a, int *n)

      while(p!=NULL);

      { int i, j = 0 ;

      printf(\

      for(i = 1 ; i <= 1000 ; i++) {

      main(){ SLIST *head;

      /**************found**************/

      int a[N]={11,12,15,18,19,22,25,29};

      if(((i % 7 == 0) || (i % 11 == 0)) && i % 77 !=

      head=creatlist(a);

      0) a[j++] = ___1___ ; }

      printf(\

      /**************found**************/

      outlist(head);

      *n = ___2___ ;}

      printf(\

      main()

      while (head->next != NULL){

      { int aa[1000], n, k ;

      fun(head);

      /**************found**************/

      printf(\

      fun ( ___3___ ) ;

      printf(\from head again :\\n\

      for ( k = 0 ; k < n ; k++ )

      outlist(head); }}

      if((k + 1) % 10 == 0) printf(\

      第一空:next 第二空:t->data 第三空:t

      else printf(\第一空:i 第二空:j 第三空:aa,&n 43.给定程序的功能是计算score中m个人的平均成绩

      aver,将低于aver的成绩放在below中,通过函数名返回

      42.给定程序中已经建立一个带有头结点的单向链表,在

      人数。例如,当

      main函数中将多次调用fun函数,每调用一次fun函数,

      socre={10,20,30,40,50,60,70,80,90},m=9时,函数返

      输出链表尾部结点中的数据,并释放该结点,使链表缩

      回的人数应该是4,below={10,20,30,40}。

      短。

      #include

      #include

      #include

      #include

      int fun(int score[], int m, int below[])

      #define N 8

      { int i, j = 0 ;

      typedef struct list

      float aver = 0.0 ;

      { int data;

      for(i = 0 ; i < m ; i++) aver += score[i] ;

      struct list *next;

      aver /= (float) m ;

      } SLIST;

      37

      for(i = 0 ; i < m ; i++)

      /**************found**************/

      if(score[i] < aver) below[j++] = ___1___ ; return j ;}

      main(){ int i, n, below[9] ;

      int score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90} ;

      /**************found**************/ n = fun(score, 9, ___2___) ;

      printf( \/**************found**************/ for (i = 0 ; i < n ; i++) printf(\\___3___) ;} 第一空:score[i] 第二空:below 第三空:below[i]

      {\{\ int i;

      printf(\ for ( i=0; i< N; i++ )

      printf(\ fun ( a, &m );

      printf (\

      printf (\ 第一空:STU 第二空:h 第三空:h

      46. 给定程序中已经建立一个带有头结点的单项链表,链表中的各结点按照数据域递增有序链接。函数fun的功能是:函数链表中数据域值相同的结点,使之只保留一个。(101)

      44.给定程序的功能是求出能整除x且不是偶数的各整数,#define N 8 并放在数组pp中,这些除数的个数由n返回。例如,若xtypedef struct list 的值为30,则有4个数符合要求,它们是1,3,5,15。 { int data; #include struct list *next; void fun(int x, int pp[], int *n) } SLIST; { int i, j = 0 ; void fun( SLIST *h) for(i = 1 ; i <= x ; i +=2 ) { SLIST *p, *q; /**************found**************/ p=h->next; if((x % i) == 0) pp[j++] = ___1___ ; if (p!=NULL) /**************found**************/ { q=p->next; *n = ___2___ ;} while(q!=NULL) main(){ int x, aa[1000], n, i ; { if (p->data==q->data) printf( \ { p->next=q->next; scanf(\/**********found**********/ /**************found**************/ free(___1___); fun(x, ___3___ ) ; /**********found**********/ for( i = 0 ; i < n ; i++ ) q=p->___2___; } printf(\ else printf(\ { p=q; 第一空: i 第二空: j 第三空:aa,&n /**********found**********/

      q=q->___3___; } } }}

      45.已知学生的记录由学号和学习成绩构成,N名学生的

      SLIST *creatlist(int *a)

      数据已经存入a结构体数组中。给定程序的功能是找出

      { SLIST *h,*p,*q; int i;

      成绩最低的学生记录,通过形参返回主函数。

      h=p=(SLIST *)malloc(sizeof(SLIST));

      #include

      for(i=0; i

      #include

      { q=(SLIST *)malloc(sizeof(SLIST));

      #define N 10

      q->data=a[i]; p->next=q; p=q; }

      typedef struct ss

      p->next=0;

      { char num[10]; int s; } STU;

      return h;}

      fun(STU a[], STU *s)

      void outlist(SLIST *h)

      {/**************found**************/

      { SLIST *p;

      ___1___ h; int i ;

      p=h->next;

      h = a[0];

      if (p==NULL)

      for ( i = 1; i < N; i++ )

      printf(\

      /**************found**************/

      else{ printf(\

      if ( a[i].s < h.s ) ___2___ = a[i];

      do{printf(\ p=p->next; }

      /**************found**************/

      while(p!=NULL);

      *s = ___3___ ;}

      printf(\

      main(){STU a[N]={ {\

      main( ){ SLIST *head;

      {\

      38

      int a[N]={1,2,2,3,4,4,4,5}; n,c1,c2,c3);} head=creatlist(a); 第一空:n 第二空:break 第三空:break printf(\list before deleting :\\n\49.函数fun的功能是进行字母转换,若形参ch中小写

      outlist(head); fun(head);

      英文字母,则转换成参应的大写英文字母;若ch中是大

      printf(\list after deleting :\\n\写英文字母,则转换成对应的小写英文字母;若是其它

      outlist(head);}

      字母则保持不变;并转换后的结果作为函数值返回。

      第一空:q 第二空:next 第三空: next

      #include

      47.给定程序的功能是实现矩阵(3行3列)的转置。 #include #include char fun(char ch) int fun(int array[3][3]) {/**********found**********/ { int i,j,arr[3][3] ; if ((ch>='a')___1___(ch<='z')) memcpy(arr, array, 9*sizeof(int)) ; return ch -'a' + 'A'; for(i = 0 ; i < 3 ; i++) if ( isupper(ch) ) for(j = 0 ; j < 3 ; j++) /**********found**********/ /**************found**************/ return ch +'a'-___2___ ; array[i][j] = ___1___ ;} /**********found**********/ main(){ int i,j; return ___3___;} int array[3][3]={{100,200,300}, main(){ char c1, c2; {400,500,600}, printf(\ {700,800,900}}; c1='w'; c2 = fun(c1); for (i=0;i<3;i++) printf(\ { for (j=0;j<3;j++) c1='W'; c2 = fun(c1); printf(\ printf(\ printf(\ c1='8'; c2 = fun(c1); /**************found**************/ printf(\ fun(___2___); 第一空:&& 第二空:’A’ 第三空:ch printf(\

      50.给定程序的功能是对指定字符在字符串a中出现的次

      for (i=0;i<3;i++)

      数进行统计,统计的数据存到b数组中。其中:字符’Z’

      { for (j=0;j<3;j++)

      出现的次数存放到b[0]中,字符’Y’出现的次数存放到

      /**************found**************/

      b[1],字符’X’出现的次数存放到b[2]中,字符’W’出

      printf(\

      现的次数存放到b[3],字符’V’出现的次数存放到b[4]

      printf(\

      中,其它字符出现的次数存到b[5]中。

      第一空:arr[j][i] 第二空:array 第三空:array[i][j]

      #include

      48.函数fun的功能是:统计长整数n的各个位上出现数#include

      字1、2、3的次数,并通过上部(全局)变量 c1、c2、void fun(char *a, int b[]) c3返回主函数。例如:当n=123114350时,结果应该是:{ int i; c1=3 c2=1 c3=2。 for (i=0; i<6; i++) b[i] = 0; #include /**************found**************/ int c1,c2,c3; for (i=0; i< ___1___(a); i++) void fun(long n) if (a[i] >= 'V' && a[i] <= 'Z') { c1 = c2 = c3 = 0; b[4-(a[i]-'V')]++; while (n) { /**************found**************/ /**********found**********/ ___2___ b[5]++;} switch(___1___){ main() /**********found**********/ { int i, b[6]; case 1: c1++;___2___; char a[100] = \/**********found**********/ /**************found**************/ case 2: c2++;___3___; fun(___3___); case 3: c3++; } printf(\

      n /= 10;}} for (i=0; i<6; i++) printf(\main(){ long n=123114350L; printf(\ fun(n); printf(\第一空:strlen 第二空:else 第三空:a,b printf(\

      39

      50.函数fun的功能是:将形参a所指数组中的前半部分元素中的值和后半部分元素中的值对换。形参n中存放数组中的数据的个数,若n为奇数,则中间的元素不动。例如:若a所指数组中的数据一次为:1、2、3、4、5、6、7、8、9,则调换后为:6、7、8、9、5、1、2、3、4。 #include #define N 9

      void fun(int a[], int n) { int i, t, p;

      /**********found**********/

      p = (n%2==0)?n/2:n/2+___1___; for (i=0; i

      /**********found**********/ a[i] = a[p+___2___]; /**********found**********/ ___3___ = t; }} main()

      { int b[N]={1,2,3,4,5,6,7,8,9}, i; printf(\ for (i=0; i

      printf(\ for (i=0; i

      第一空:1 第二空:i 第三空:a[p+i]

      #include #include int fun( int high )

      { int sum = 0, n=0, j, yes; /************found************/

      while ((high >= 2) ___1___ (n < 10)) { yes = 1;

      for (j=2; j<=high/2; j++ ) if (high % j ==0 ){

      /************found************/ yes=0; ___2___; }

      if (yes) { sum +=high; n++; } /************found************/ ___3___; } return sum ;} main ( ){

      printf(\

      第一空:&& 第二空:break 第三空:high=high-1

      54.给定程序的功能是删除w数组中下标为k的元素中的值。程序中,调用了getindex、arrout和arrdel三个函数,getindex用以输入所删除元素的下标,函数中对输入的下标进行检查,若越界,则要求重新输入,直到正确为止。arrout用以输出数组中的数据,arrdel进行所要求的删除操作。 #include #define NUM 10

      arrout ( int *w, int m ) { int k;

      /************found************/ for (k = 0; k < ___1___; k++)

      52.给定程序的功能是把s串中所有的字符前移一个位 printf (\置,串中的第一个字符移到最后。例如:s串中原有的字 printf (\

      符串为:Mn.123xyZ,则调用函数后,s串中的内容为:arrdel ( int *w, int n, int k ) n.123xyZM { int i; #include for ( i = k; i < n-1; i++ ) #define N 81 w[i] = w[i+1]; n--; fun ( char *s ) /************found************/ { char b[N] ; return ___2___;} sprintf(b, \getindex( int n ) /**************found**************/ { int i; strcpy(___1___) ;} /************found************/ main( ) ___3___ { char a[ N ] ; { printf(\ printf ( \ scanf (\ printf ( \original string is : \); puts( a ); } while( i < 0 || i > n-1 ); /**************found**************/ return i;} fun ( ___2___ ); main( ) printf ( \{ int n, d, /**************found**************/ a[NUM]={21,22,23,24,25,26,27,28,29,30}; ___3___ ( a );} n = NUM; 第一空:s,b 第二空:a 第三空:puts printf (\

      arrout ( a, n );

      53.给定程序的功能是计算并输出high以内最大的10个

      d = getindex( n ); n = arrdel ( a, n, d );

      素数和。high由主函数传给fun函数。例如:high值为

      printf (\the data after delete :\\n\

      100,函数的值为732。

      40

      arrout( a, n );}

      第一空:m 第二空:n 第三空: do

      h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

      { s=(NODE *)malloc(sizeof(NODE));

      55.给定程序的功能是从字符串s尾部开始,按逆序把在

      s->data=rand();

      其中出现的每相邻的两个字符,紧随其后重复出现一次,

      s->next=p->next;

      放在一个新串t中,若字符串s中头部有剩余的单个字

      p->next=s;

      符也重复,放在t的最后。例如:当s中的字符串

      p=p->next; }

      为:”12345”时,则t中的字符串应该

      p->next=NULL;

      为:”5454323211”

      return h;}

      #include

      outlink(NODE *h, FILE *pf)

      #include

      { NODE *p; p = h->next;

      void fun (char *s, char *t)

      fprintf(pf ,\

      { int i, j, sl;

      while(p)

      sl = strlen(s);

      { fprintf(pf ,\

      for(i=sl-1,j=0;i>=0;i-=2)

      fprintf (pf,\

      { t[j++] = s[i];

      outresult(int s, FILE *pf)

      if (i-1 >= 0) t[j++] = s[i-1];

      {fprintf(pf,\sum of even numbers:

      /************found************/

      %d\\n\

      t[j++] = ___1___;

      main(){ NODE *head; int even;

      /************found************/

      head=creatlink(12);

      if (i-1 ___2___ 0)

      head->data=9000;

      t[j++]=s[i-1]; }

      outlink(head , stdout);

      t[j] = '\\0';}

      even=fun(head);

      main()

      printf(\

      { char s[100], t[100];

      outresult(even, stdout);}

      printf(\enter string s:\scanf(\

      第一空:NODE 第二空:h->next 第三空:p->next

      s);

      /************found************/ 57.给定程序的功能是把在字符串s中出现的每个字符, fun(___3___); 紧随其后重复出现一次,形成一个新串放在t中,且在t printf(\中把原相邻字符的位置进行了互换。例如:当s中的字第一空:s[i] 第二空:>= 第三空:s,t 符串为:”12345”时,则t中的字符串应该

      为:”2211443355”。

      56. 给定程序的功能是建立一个带有头结点的单向链

      #include

      表,并用随机函数为各结点赋值。函数fun的功能是将

      #include

      单向链表结点(不包括结点)数据域为偶数的值累加起

      void fun (char *s, char *t)

      来,并且作为函数值返回。

      { int i,j,sl;

      #include

      /************found************/

      #include

      sl = ___1___(s);

      typedef struct aa

      for (i=0, j=0; i

      { int data; struct aa *next; }NODE;

      { if (i+1 < sl)

      int fun(NODE *h)

      { t[2*j] = s[i+1];

      { int sum = 0 ;

      t[2*j +1] = s[i+1];

      /***********found**********/

      j++; }

      ___1___ *p;

      t[2*j] = s[i]; t[2*j +1] = s[i];

      /***********found**********/

      /************found************/

      p=___2___;

      ___2___; }

      while(p)

      t[2*sl] = '\\0';}

      { if(p->data%2==0)

      main()

      sum +=p->data;

      { char s[100], t[100];

      /***********found**********/

      printf(\enter string s:\scanf(\

      p=___3___; }

      s);

      return sum;}

      /************found************/

      NODE *creatlink(int n)

      fun(___3___);

      { NODE *h, *p, *s, *q;

      printf(\

      int i, x;

      41

      第一空:strlen 第二空:j=j+1 第三空:s,t

      s=s+j*1.0/(2*i+1); j*=-1; }

      58.给定程序的功能是根据公式求P的值,结果由函数值

      /**************found**************/

      m!带回。m与n为两个正整数且要求m>n。P? ___2___=s;}

      n!(m?n)!main(){ int n=15; float s;

      例如:m=11,n=4时,运行结果为330.000000。 /**************found**************/ #include fun(___3___); long jc(int m) printf(\{ long s=1; int i ; 第一空:1 第二空:*sn 第三空:&s,n /**************found**************/

      61.给定程序的功能是把s 串中所有的字母改写该字母

      for(i=1;i<=m;i++) s=___1___ ;

      的下一个字母,字母z改写成字母a。大写字母仍为大写

      return s;}

      字母,小写字母仍为小写字母,其它字符不变。

      float fun(int m, int n)

      #include

      { float p;

      #include

      /**************found**************/

      #include

      p=1.0*jc(m)/jc(n)/jc(___2___) ;

      #define N 81

      /**************found**************/

      fun ( char *s )

      ___3___;}

      {/**************found**************/

      main(){ printf(\

      char *p = ___1___ ;

      第一空:s*i 第二空:m-n 第三空:return p

      while(*p) {

      59.给定程序的功能是把a数组中的n个数,和b数组中/**************found**************/ 逆序的n个数一一对应相乘求平方,结果存在c数组中。 if(*p == 'Z') *p = ___2___ ; 例如:当a数组中的值是:1、3、5、7、8,b数组中的/**************found**************/ 值是:2、3、4、5、8,c中存放的数据是:64、225、400、 else if(*p == 'z') *p = ___3___ ; 441、256。 else if(isalpha(*p)) *p = (*p) + 1 ; #include p++ ; }} void fun(int a[], int b[], int c[], int n) main( ){ char a[N]; { int i; printf ( \ for (i=0; i

      62.给定程序中,函数fun的功能是:有N×N矩阵,根

      /**************found**************/

      据给定的m(m

      fun(___2___, 5);

      左边置为0。例如,N=3,m=2,则下列矩阵

      printf(\

      1 2 3 程序执行结果为 0 0 1

      /**************found**************/

      4 5 6 0 0 4

      for (i=0; i<5; i++) printf(\

      7 8 9 0 0 7

      printf(\

      #include

      第一空:c[i] 第二空:a,b,c 第三空:c[i]

      #define N 4

      60.给定程序的功能是根据公式计算S,计算结果通过形void fun(int (*t)[N], int m) 参指针sn传回;n通过形参传入。 { int i, j;

      /**********found**********/ 11111Sn???????例如,若n的值为15

      for(i=0; i=0; j--) 时,输出结果是:S=0.769788 N=15。

      /**********found**********/ #include

      t[i][j+___2___ ]=t[i][j]; void fun(float *sn, int n)

      /**********found**********/ {/**************found**************/

      for(j=0; j<___3___; j++) int i,j=___1___;

      t[i][j]=0; }} float s=0.0;

      main() for(i=0;i<=n;i++) {

      { int t[][N]={21,12,13,24,25,16,47,

      42

      38,29,11,32,54,42,21,33,10}, i, j, m; printf(\ for(i=0; i

      printf(\ printf(\

      printf(\scanf(\ fun(t,m);

      printf(\ for(i=0; i

      printf(\ printf(\

      第一空:i++ 第二空:m 第三空:m

      63.给定程序的功能是建立一个带有头结点的单向链表,并用随机函数为各结点赋值。函数fun的功能查找结点数据域最大值,并且作为函数值返回。 #include #include typedef struct aa

      { int data; struct aa *next; }NODE; int fun(NODE *h) { int max = 0 ;

      /***********found**********/ ___1___ *p; p=h->next;

      /***********found**********/ max=___2___ while(p)

      { if(p->data>max) max=p->data;

      /***********found**********/ ___3___ } return max;}

      NODE *creatlink(int n) { NODE *h, *p, *s, *q; int i, x;

      h=p=(NODE *)malloc(sizeof(NODE)); for(i=1; i<=n; i++)

      { s=(NODE *)malloc(sizeof(NODE)); s->data=rand(); s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h;}

      outlink(NODE *h, FILE *pf) { NODE *p; p = h->next;

      fprintf(pf ,\ while(p)

      { fprintf(pf ,\

      43

      fprintf (pf,\}

      outresult(int s, FILE *pf)

      {fprintf(pf,\main()

      { NODE *head; int even; head=creatlink(12); head->data=9000;

      outlink(head , stdout); even=fun(head);

      printf(\ outresult(even, stdout);}

      第一空:NODE 第二空:p->data 第三空:p=p->next 64. 给定程序的功能是把一个字符串的字符复制到另外一个字符串中。

      void cpystr(char *ps,char *pd) { while(*ps!='\\0') { *pd=*ps; pd++;

      /******found******/ ___1___; } /******found******/ *pd=___2___;} main(){

      char *pa=\ pb=b;

      /******found******/ ___3___

      printf(\ return 0;}

      第一空:ps++ 第二空:’\\0’或0 第三空:strcpy(pa,pb);

      65. 给定程序的功能是:从键盘输入一个字符串(长度不超过80个字符),依次扫描字符串中的小写字母o,每次将小写字母o的左右字符串部分作交叉换位,即左边字符串移到小写字母o的右边,而原先右边的则返之。并把小写字母o删除,依次直至小写字母o处理完,之后已处理的字符串出到屏幕。例如:输入字符串为:”123oabco98”,处理后输出为”98123abc”。 void main()

      {int i=0,j=0,sj=0,bs; char ch[80]; char *s,*f;

      printf(\ scanf(\

      while (ch[i]!='\\0') { /******found******/ if ___1___ {sj++;}

      /******found******/ ___2___; } for (i=0;i

      { if (ch[j]=='o') /******found******/ ___3___; j++; } f=&ch[j+1]; ch[j]='\\0'; s=ch;

      strcat(f,s); strcpy(ch,f); }

      printf(\

      第一空:(ch[i]==’o’) 第二空:i++ 第三空:break 66. 给定程序的功能是:从键盘输入一个字符串(长度不超80个字符),依次扫描字符串的小写字母o,每次将小写字母o左侧所有小写字母转换为大写字母,大写字母转换为小写字母。并把小写字母o删除,依次直至小写字母o处理完,之后把已处理的字符串输出到屏幕。例如:输入字符串为”aA1BoCao”,处理后输出为”aA1BcA”。输入字符串”aAobC”,输出为”AabC”。 #include #include void main()

      {int i=0,j=0,nulin,sj=0,m; char ch[80];

      printf(\ scanf(\

      while (ch[i]!='\\0') { if (ch[i]=='o') sj++; i++; }

      for (i=0;i

      /***************found***************/ ___1___;

      for (m=0;m

      {if (ch[m]>='a' && ch[m]<='z') ch[m]=ch[m]-32;

      /***************found***************/ ___2___

      if (ch[m]>='A' && ch[m]<='Z') ch[m]=ch[m]+32; } if (m>=j)

      ch[m]=ch[m+1]; }

      /***************found***************/ ___3___;}

      printf(\

      第一空:nulin=strlen(ch); 第二空:else 第三空:ch[nulin-1]=’\\0’;

      67. 给定函数countValue(int n),它的功能是:求n以内(不包括n)同时被3与7整除的所有自然数之和的平

      44

      方根s,s作为函数返回值。主程序调用该函数输出n为

      1000时的函数值153.909064。 /******found******/

      ___1___ countValue(int n) { double xy=0.0; int i;

      /******found******/ for(i=8;__2___;i++)

      if(i%3==0&&i%7==0) xy+=i; xy=sqrt((double)xy); /******found******/ ___3___;} main()

      { printf(\第一空:double 第二空:i

      for(i=1;i

      if(i==0&&i%7==0) /******found******/ ___2___; return xy;} main(){

      /******found******/

      printf(\

      第一空:double 第二空:xy=xy+sqrt((double)i) 第三空:countValue(1000)

      69. 给定程序的功能分别求7个学生三门课程的平均成绩,在主程序中输出各学生平均成绩和最大平均成绩av。 float fun(float a,float b,float c) { float sum,aver; sum=a+b+c;

      /**********found************/ ___1___; return(aver);}

      main(){ float a[7][3]={{80,90.5,81.5}, {70,69.8,90.5}, {68,97,99.0}, {86.5,89,95}, {78,96,90}, {87.5,89,92}, {64.5,80,78}}; float av=0.0,b[7];int i; for (i=0;i<7;i++)

      /**********found************/ {b[i]=___2___;

      /**********found************/ if ___3___

      av=b[i];} for (i=0;i<7;i++)

      printf(\ printf(\

      第一空:aver=sum/3.0 第b[i]=fun(a[i][0],a[i][1],a[i][2]); 第三空:if(av

      max,cnt,pj);}

      第一空:max=xx[0];第二空: for(i=0,k=0;i

      72. 给定程序的功能是找出所有100以内(含100)满足I,I+4,I+10都是素数的整数I(I+10也以100以内)的个数cnt以及这些I之和sum。 int cnt,sum;

      int isPrime(int number) { int i,tag=1;

      if(number==1) return 0;

      for(i=2;tag&&i<=number/2;i++)

      /***************found***************/ if(___1___) tag=0; return tag;} void countValue()

      { int I,count=0,xx[30]; int j,k,m; cnt=0; sum=0;

      /***************found***************/ for(I=1;___2___;I++)

      if(isPrime(I)) {xx[count]=I;count++;} for(I=0;I

      if (isPrime(xx[I]+4)&&isPrime(xx[I]+10)) /***************found***************/ {___3___;}}

      void main(){ cnt=sum=0;

      countValue();printf(\printf(\

      第一空:number%i==0 第二空:I<90 第三空:cnt++;sum+=xx[I]

      73.给定程序的功能是对从键盘输入的字符数组xx(不超过80个字符),按字符从大到小的顺序进行排序,排序后的结果存入字符串数组xx中。例如:输入:dAe,BfC.结果:fedCBA.

      #include void main()

      { char xx[80] ; int numi,numj; char ch;

      printf(\ scanf(\

      for (numi=0;numi

      /***************found***************/ for (numj=___1___;numj

      /***************found***************/

      ___2___;

      xx[numi]=xx[numj];

      /***************found***************/

      ___3___;}

      printf(\

      第一空:numi+1 第二空:ch=xx[numi] 第三空:xx[numj]=ch

      45

      70.给定程序的功能是用递归法计算n!。用递归方法计算n!,可使用如下公式表示

      ┌1 (n=0,1) n!= ┤

      └n×(n-1)!(n>1) #include long ref(int n) { long m;

      if (n<0) printf(\/************found************/ else if (___1___) m=1;

      /************found************/ else ___2___; return(m);}

      main(){ int n; long y;

      printf(\/************found************/ scanf(\ y=ref(n);

      printf(\ return;} 第一空:(n==0||n==1)第二空:m=ref(n-1)*n 第三空:&n

      71.给定程序的功能是求出数组中的最大数max及最大数的个数cnt数组xx中值能被3整除或能被7整除的算术平均值pj(保留职位小数),结果max,cnt,pj输出到屏幕。

      #define N 20 void main() { int max;

      int cnt,xx[N]={78,43,56,34,43,32,85, 43,46,10,90,34,90,3,52,61,42,89,90,54}; float pj;

      long j=0; int I,k;

      /*************found************/ ___1___

      /*************found************/ for(___2___;I

      /*************found************/ {if (xx[I]>max) ___3___; if (xx[I]%3==0||xx[I]%7==0) {j+=xx[I];k++;} } for (I=0,cnt=0;I

      printf(\

      74. 给定程序的功能是:对字符数组xx中字符按给定的替代关系对所有字符进行替代,仍存入数组xx的对应的位置上。替代关系:f(p)=p*11 mod 256(p是数组xx中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符是大写字母或计算后f(p)值小于等于32, 则该字符不变,否则将f(p)所对应的字符进行替代。 void main() { char xx[80]; int i,j;

      printf(\ scanf(\

      /***************found***************/ for (i=0;___1___;i++)

      if((('A'<=xx[i])&&(xx[i]<='Z'))|| (((xx[i]*11) % 256 )<=32))

      /***************found***************/ ___2___ else

      /***************found***************/ xx[i]=___3___;

      printf(\第一空:i

      struct stu_list { int num;

      char name[20]; char sex; float score;

      }s[5]={{9801,\

      {9802,\ {9803,\ {9804,\ {9805,\main()

      { int i,c=0;

      float ave,sum=0; for (i=0;i<5;i++) {

      /***************found***************/ sum+=___1___;

      /***************found***************/ if (___2___) c+=1;} printf(\

      /***************found***************/ ___3___;

      printf(\ return; }

      第一空:sum+=s[i].score 第二空:if(s[i].score<60) c+=1 第三空:ave=sum/5;

      76. 给定程序的功能是在三位整数(100至999)中寻找符合下面条件的整数,并依次从小到大存入数组b[]中;它既是完全平方数,又有两位数相同,例如144,676等。

      46

      函数int jsValue(int n)判断参数是否满足该条件,如果满足该条件函数返回值为1,否则返回值为0。 #include int jsValue(int n) { int j,k=0;

      int n1,n2,n3; j=10; while(j*j<=n) { if (n==j*j) { n1=n / 100;

      /***************found***************/ n2=___1___; n3=n % 10;

      if(n1==n2||n1==n3||n2==n3) k=1; }

      /***************found***************/ ___2___; } return k;} main()

      { int b[20],num,i;

      for (i=100,num=0;i<=999;i++) if (jsValue(i)==1) { b[num]=i;

      /***************found***************/ ___3___; }

      for (i=0;i

      printf(\第一空:(n/10) 第二空:j++; 第三空:num++; 77. 给定程序的功能是从键盘输入3行3列矩阵的各个元素,然后输出对角线元素之和。 int fun()

      { int a[3][3],sum; int i,j;

      /***************found**************/ sum=___1___;

      for (i=0;i<3;i++) {for (j=0;j<3;j++)

      /***************found**************/

      scanf(\ for (i=0;i<3;i++)

      /***************found**************/ ___3___

      printf(\main(){ fun();}

      第一空:sum=0 第二空:& 第三空:sum=sum+a[i][i]; 78. 给定程序的功能是求下列分数序列的前n项之和。n值从键盘输入,和值通过函数值返回主程序输入。

      23581321,,,,,,??例如:若n=5,则应该输出:12358188.391667。

      double fun(int n)

      { int a,b,c,k; double s; s=0.0; a=2;

      /***************found***************/ ___1___;

      for (k=1;k<=n;k++) { s=s+(double)a/b; c=a; a=a+b;b=c; }

      /***************found***************/ ___2___;} main(){ int n;

      /***************found***************/ printf(\ scanf(\ clrscr();

      printf(\the value of function is: %lf\\n\fun(n));}

      第一空:b=1第二空:return s 第三空:&n

      79. 给定程序的功能是读入五位用户的姓名和电话号码,按姓名的字典顺序排列后,输出用户的姓名和电话号码。函数getdata读入五位用户的姓名和电话号码。getsort函数把数据按姓名的字典顺序排序。outdata输出最后的结果。 #define N 5 typedef struct { char name[20]; char num[10]; }USER;

      /***************found***************/ getdata(___1___) { int i;

      printf(\ for(i=0;i

      {printf(\

      /***************found***************/ printf(\/***************found***************/ printf(\getsort (USER *sp) { int i,j,k; USER temp;

      for(i=0;i

      for(j=i+1;j

      if (strcmp(sp[k].name,sp[j].name)>0) k=j; temp=sp[k];sp[k]=sp[i];sp[i]=temp; }} outdata(USER *sp) { int i;

      printf(\ for (i=0;i

      printf(\main(){ USER sp[N],temp; getdata(sp); getsort(sp); outdata(sp);}

      第一空:USER *sp 第二空:gets 第三空:gets

      47

      80. 给定程序的功能是读入五位用户的姓名和电话号码,按姓名的字典顺序排列后,输出用户的姓名和电话号码。函数getdata读入五位用户的姓名和电话号码。getsort函数把数据按姓名的字典顺序排序。outdata输出最后的结果。 #define N 5 typedef struct { char name[20]; char num[10]; }USER;

      getdata(USER *sp) { int i;

      printf(\ for(i=0;i

      {printf(\

      printf(\ printf(\getsort (USER *sp) { int i,j,k;

      /***************found***************/ ___1___;

      for(i=0;i

      for(j=i+1;j

      if (strcmp(sp[k].name,sp[j].name)>0) k=j; temp=sp[k];

      /***************found***************/ ___2___;

      /***************found***************/ ___3___; }} outdata(USER *sp)

      { int i; printf(\ for (i=0;i

      printf(\main(){ USER sp[N],temp; getdata(sp); getsort(sp); outdata(sp);}

      第一空:USER temp 第二空:sp[k]=sp[i]; 第三空:sp[i]=temp;

      81.给定程序的功能是找出方阵中每列最小元素以及所在的行号。函数findmin找出每列中最小元素所在行号,函数outdata输出方阵中每列最小元素及其所在行号。 #define M 4 main()

      { int s[M][M]={{14,23,52,3},

      {34,22,52,41},{12,15,8,9},{54,98,23,21}}; int im[M]; findmin(s,im);

      outdata(s,im);}

      findmin(int a[][M],int ln[]) { int i,j,t; for (i=0;i

      { t=0;

      /***************found***************/ for(j=1;___1___;j++)

      if(a[j][i]

      /***************found***************/ ___2___; }} outdata(int(*a)[M],int *ln) { int i,j;

      printf(\ for(i=0;i

      printf(\ printf(\

      printf(\ for (i=0;i

      /***************found***************/ printf(\ printf(\

      第一空:j

      { int s[M][M]={{14,23,52,3}, {34,22,52,41}, {12,15,8,9}, {54,98,23,21}}; int im[M],sum; findmax(s,im); outdata(s,im);}

      findmax(int a[][M],int ln[]) { int i,j,t; for (i=0;i

      for(j=1;j

      if(a[i][j]>a[i][t])

      /***************found***************/ ___1___; ln[i]=t; }}

      outdata(int(*a)[M],int *ln) { int i,j,sum;

      printf(\/***************found***************/ ___2___;

      for(i=0;i

      { for (j=0;j

      printf(\ printf(\

      printf(\ for (i=0;i

      /***************found***************/

      48

      {printf(\ sum=sum+ a[i][ln[i]]; } printf(\

      第一空:t=j;第二空:sum=0; 第三空:ln[i] 83. 定程序和功能是main函数读入数组a的各元素值,inver函数逆序后重新放置数组a元素的值。 #define N 10

      void invert(int *s,int i,int j) { int t; if (i

      /***************found***************/ *(s+i)=___1___; *(s+j)=t;

      /***************found***************/ invert(s,___2___,j-1); }} main()

      { int a[N],i;

      for (i=0;i

      { printf(\

      /***************found***************/ scanf(\ invert(a,0,N-1); for (i=0;i

      printf(\ printf(\}

      第一空:s[j] 第二空:i+1 第三空:a+i

      84. 定程序的功能是:将无符号八进制数字构成的字符串转换为十进制整数。例如,输入的字符串为:556,则输入十进制整数366。 main()

      /***************found***************/ { char ___1___,s[6]; int n; p=s; gets(p);

      /***************found***************/ n=___2___;

      /***************found***************/ while(___3__!='\\0')

      n=n*8+*p-'0'; printf(\第一空:*p 第二空:*p-‘0’ 第三空:*(++p) 85. 定函数int MySearch(char *str,char *s)的功能是:统计字符串s在字符串str中出现的次数。例如,若输入字符串”12 123 12345”和”23”,则应输出2(表示字符串”23”在字符串”12 123 12345”中出现了两次)。若输入字符串”33333”和”33”,则应输出4(表示字符串”33”在字符串”33333”出现了四次)。 int MySearch( char* str, char* s ) { char* p; int n =0;

      for( ; *str; )

      /***************found***************/

      if( ( p = strstr( str, s ) ) != ___1___ ) { n++; str=p+1; } else

      /***************found***************/ ___2___;

      /***************found***************/ return( ___3___ );} main()

      { char str1[81], str2[21];

      printf(\ gets(str1);

      printf(\ gets(str2);

      printf( \times\\n\第一空:NULL 第二空:*str=0 第三空:n

      86.给定程序中已建立一个带有头结点的单向链表,链表中的各结点按结点数据域中的数据从小到大顺序链接。函数fun的功能是:把形参x的值放入一个新结点并插入到链表中,插入后各结点仍保持从小到大顺序排列。

      #define N 8 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 && x>p->data) { /**********found**********/ q=___2___; p=p->next; } s->next=p;

      /**********found**********/ q->next=___3___;}

      SLIST *creatlist(int *a)

      { SLIST *h,*p,*q; int i;

      h=p=(SLIST *)malloc(sizeof(SLIST)); for(i=0; i

      { q=(SLIST *)malloc(sizeof(SLIST)); q->data=a[i]; p->next=q; p=q;} p->next=0; return h;}

      void outlist(SLIST *h) { SLIST *p; p=h->next; if (p==NULL)

      printf(\

      49

      else

      { printf(\

      do { printf(\ p=p->next; } while(p!=NULL); printf(\main()

      { SLIST *head; int x;

      int a[N]={11,12,15,18,19,22,25,29}; head=creatlist(a);

      printf(\ outlist(head);

      printf(\ scanf(\ fun(head,x);

      printf(\ outlist(head);}

      第一空:x 第二空:p 第三空:s

      87. 给定程序中,函数fun的功能是:读自然数1~10以及它们的平方根写到名为myufile3.txt的文本文件中,然后再顺序读出显示屏幕上。 #include #include int fun(char *fname )

      { 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 88. 定程序的功能是:调用fun函数建立班级通讯录。通讯录中记录每个学生的编号、姓名和电话号码。班级的人数和学生信息从键盘输入,每个人的信息作为一个数据块写到myfile5.dbf的二进制文件中。 #define N 5 typedef struct

      { int num;

      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(\ else

      printf(\void check()

      { FILE *fp; int i; STYPE s[10];

      if((fp=fopen(\ { printf(\

      printf(\ printf(\ for(i=0; i

      { fread(&s[i],sizeof(STYPE),1, fp); printf(\

      s[i].num,s[i].name,s[i].tel); } fclose(fp);}

      第一空:STYPE 第二空:FILE 第三空:fp

      89.定程序的功能是将十进制整数m转换成k进制(2≤k≤9)数的数字输出。例如,如果输入8和2,则应该输出1000。

      #include

      void fun( int m, int k ) { int aa[20], i;

      for( i = 0; m; i++ ) { /**********found**********/ aa[i] = ___1___;

      /**********found**********/ m /= ___2___; } for( ; i; i-- )

      50

      /**********found**********/

      printf( \main()

      { int b, n;

      printf( \enter a number and a base:\\n\

      scanf( \ fun( n, b );}

      第一空:m%k 第二空:k 第三空:aa

      90. 给定程序的功能是将在字符串s中出现、而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。例如:当s=”112345”,t=”2467”时,u中的字符串为”1135”。

      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(\

      printf(\第一空:break 第二空:s[i] 第三空:*u

      91. 给定程序的功能是将大写字母转换为对应的小写字母的第五个字母;若小写字母为v~z,使小写字母的值减去21。转换后的小写字母作为函数值返回。例如,若形参使字母A,则转换为小写字母f;若形参为字母W,则转换为小写字母b。 char fun(char c)

      { 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 ) ) {

      本文来源:https://www.bwwdw.com/article/trgp.html

Top