二级C语言50题库(简洁背诵复习版)[1]1.doc_第1页
二级C语言50题库(简洁背诵复习版)[1]1.doc_第2页
二级C语言50题库(简洁背诵复习版)[1]1.doc_第3页
二级C语言50题库(简洁背诵复习版)[1]1.doc_第4页
二级C语言50题库(简洁背诵复习版)[1]1.doc_第5页
已阅读5页,还剩66页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第1套题一、程序填空题#include #include #define N 5typedef struct int num; Char name 10; char tell10;STYPE;void check();填空答案:(1)STYPE (2)FILE (3)fp/*found*/int fun(STYPE STYPE *std)/*found*/ FILE *fp; int i; if(fp=fopen(myfile5.dat,wb)=NULL) return(0); printf(nOutput data to file !n); for(i=0; iN; i+)/*found*/ fwrite(&stdi, sizeof(STYPE), 1,fp); fclose(fp); return (1); 二、程序改错题#include #include void fun (char *s, char *t) int i, sl;参考答案:(1) for(i=0;isl;i+) (sl是字母l不是数字1) (2) t2*sl=0或tsl+sl=0 sl = strlen(s);/*found*/ for( i=0; i=sl; i +) ti = si; for (i=0; isl; i+)tsl+i = ssl-i-1;/*found*/ tsl+sl = 0;三、程序编写题 (对应题库88套编程题-特殊方法练习)第2套题一、程序填空题/*found*/void WriteText(FILE *fw) char str81; printf(nEnter string with -1 to end :n); gets(str);参考答案:(1) *fw (2) str (3) str while(strcmp(str,-1)!=0) /*found*/ fputs(str,fw); fputs(n,fw); gets(str); void ReadText(FILE *fr) char str81; printf(nRead file and output to screen :n); fgets(str,81,fr); while( !feof(fr) ) /*found*/ printf(%s,str); fgets(str,81,fr); 二、程序改错题#include /*found*/void fun (long s, long t) long sl=10; *t = s % 10;参考答案:(1) void fun(long s,long *t)(2) s1=s1*10; while ( s 0) s = s/100; *t = s%10 * sl + *t;/*found*/S1=s1*10; 三、程序编写题 (对应教材33题特殊方法练习)第3套题一、程序填空题#include #include int fun(char *fname ) FILE *fp; int i,n; float x; if(fp=fopen(fname, w)=NULL) return 0; for(i=1;i=10;i+)/*found*/参考答案(1)fp(2)fclose(fp)(3)myfile3.txt fprintf(_1_,%d %fn,i,sqrt(double)i); printf(nSucceed!!n);/*found*/ _2_; printf(nThe data in file :n);/*found*/ if(fp=fopen(_3_,r)=NULL) return 0; fscanf(fp,%d%f,&n,&x); while(!feof(fp) printf(%d %fn,n,x); fscanf(fp,%d%f,&n,&x); fclose(fp); return 1;二、程序改错题#include #include void fun ( int n, int *a )参考答案(1)for(i=j+1;in;i+) (2)p=i; int i, j, p, t; for ( j = 0; jn-1 ; j+ ) p = j;/*found*/ for ( i=j+1; iai )/*found*/ t=i; if ( p!=j ) t = aj; aj = ap; ap = t; 三、程序编写题 (对应题库96套编程题特殊方法练习)第4套题一、程序填空题#include #include int fun(char *source, char *target) FILE *fs,*ft; char ch;参考答案:(1)r (2)fs (3)ft/*found*/ if(fs=fopen(source, _1_)=NULL) return 0; if(ft=fopen(target, w)=NULL) return 0; printf(nThe data in file :n); ch=fgetc(fs);/*found*/ while(!feof(_2_) putchar( ch );/*found*/ fputc(ch,_3_); ch=fgetc(fs); fclose(fs); fclose(ft); printf(nn); return 1;二、程序改错题#include void fun (long s, long *t) int d; long sl=1; *t = 0; while ( s 0) d = s%10;参考答案:(1)if (d%2=0)(2) s/=10;/*found*/ if (d%2=0) *t=d* sl+ *t; sl *= 10; /*found*/ s = 10; 三、程序编写题 (对应题库75套编程题特殊方法练习)第5套题一、程序填空题#include #include #define N 8typedef struct list int data; struct list *next; SLIST;void fun( SLIST *h, int x) SLIST *p, *q, *s; s=(SLIST *)malloc(sizeof(SLIST);/*found*/参考答案:(1)x (2)p (3)s s-data=_1_; q=h; p=h-next; while(p!=NULL & xp-data) /*found*/ q=_2_; p=p-next; s-next=p;/*found*/ q-next=_3_;二、程序改错题#include long fun (long num)参考答案:(1)long k=1;(2)num/=10;/*found*/ long k; do k*=num%10 ;/*found*/ num=10 ; while(num) ; return (k) ;三、程序编写题 (对应题库87套编程题特殊方法练习)第6套题一、程序填空题#include #include #define N 8typedef struct list int data; struct list *next; SLIST;void fun( SLIST *p) SLIST *t, *s; t=p-next; s=p; while(t-next != NULL) s=t;/*found*/参考答案:(1) next (2) t-data (3) t t=t-_1_; /*found*/ printf( %d ,_2_); s-next=NULL;/*found*/ free(_3_);二、程序改错题#include 参考答案:(1) void fun(char *a) (2) print(%c,*a);/*found*/fun (char a) if ( *a ) fun(a+1) ;/*found*/ printf(%c *a) ; 三、程序编写题 (对应题库56套编程题特殊方法练习)第7套题一、程序填空题void fun( SLIST *h) SLIST *p, *q; p=h-next; if (p!=NULL) q=p-next; while(q!=NULL) if (p-data=q-data) p-next=q-next;/*found*/ free(_1_);/*found*/参考答案:(1) q (2) next(3) next q=p-_2_; else p=q;/*found*/ q=q-_3_; 二、程序改错题void fun(int a, int n) int i, j, t, p; for (j = 0 ;j n-1 ;j+) 参考答案:(1)缺分号(2) p = i;/*found*/ p = j for (i = j+1;i n; i+) if(ai next;/*found*/ while(p!=_1_) n+;/*found*/参考答案:(1)0或NULL(2)n (3)head,ch if (p-data=ch) return _2_; else p=p-next; return 0;main() SLIST *head; int k; char ch; char aN=m,p,g,a,w,x,r,d; head=creatlist(a); outlist(head); printf(Enter a letter:); scanf(%c,&ch);/*found*/ k=fun(_3_); if (k=0) printf(nNot found!n); else printf(The sequence number is : %dn,k);二、程序改错题#include #include #include 参考答案:(1) for(i=0,t=0;pi;i+)(2) ct=0;fun ( char *p) int i,t; char c80;/*found*/ For (i = 0,t = 0; pi ; i+) if(!isspace(*(p+i) ct+=pi;/*found*/ ct=0; strcpy(p,c);三、程序编写题 (对应题库86套编程题特殊方法练习)第9套题一、程序填空题void fun( SLIST *h, int *n)参考答案:(1) *n (2) next (3) head SLIST *p;/*found*/ _1_=0; p=h-next; while(p) (*n)+;/*found*/ p=p-_2_; main() SLIST *head; int aN=12,87,45,32,91,16,20,48, num; head=creatlist(a); outlist(head);/*found*/ fun(_3_, &num); printf(nnumber=%dn,num);二、程序改错题char * fun (char *s, char *t ) char *p , *r, *a;参考答案:(1) a=NULL; (2) if(*r=*p)/*found*/ a = Null; while ( *s ) p = s; r = t; while ( *r )/*found*/ if ( r = p ) r+; p+; else break; if ( *r = 0 ) a = s; s+; return a ;三、程序编写题 (对应题库94套编程题特殊方法练习)第10套题一、程序填空题int fun( SLIST *h) SLIST *p; int s=0; p=h-next; while(p)参考答案:(1) data (2) next (3) head /*found*/ s+= p-_1_;/*found*/ p=p-_2_; return s;main() SLIST *head; int aN=12,87,45,32,91,16,20,48; head=creatlist(a); outlist(head);/*found*/ printf(nsum=%dn, fun(_3_);二、程序改错题void fun (char *s, char *t1, char *t2 , char *w) char *p , *r, *a; strcpy( w, s ); while ( *w )参考答案:(1) while(*r) (2) *a=*r;a+;r+; p = w; r = t1;/*found*/ while ( r ) if ( *r = *p ) r+; p+; else break; if ( *r = 0 ) a = w; r = t2; while ( *r )/*found*/ *a = *r; a+; r+ w += strlen(t2) ; else w+; 三、程序编写题 (对应题库85套编程题特殊方法练习)第11套题一、程序填空题int fun(char (*ss)N, int *n)参考答案:(1)M (2) (3)k int i, k=0, len= N;/*found*/ for(i=0; i_1_; i+) len=strlen(ssi); if(i=0) *n=len;/*found*/ if(len _2_ *n) *n=len; k=i; /*found*/ return(_3_);二、程序改错题#include #include char* fun( char tt )参考答案:(1)if(a=tti)&(tti=z) (2)tti-=32; int i; for( i = 0; tti; i+ )/*found*/ if( a = tti )|( tti = z ) )/*found*/ tti += 32; return( tt );三、程序编写题 (对应题库62套编程题记程序 背答案)第12套题一、程序填空题#include void fun(char *s) int i, j=0, k=0; char t180, t280; for(i=0; si!=0; i+) if(si=0 & si=9)参考答案:(1) j+ (2) si=t1i (3) j /*found*/ t2j=si; _1_; else t1k+=si; t2j=0; t1k=0;/*found*/ for(i=0; ik; i+) _2_;/*found*/ for(i=0; i_3_; i+) sk+i=t2i;二、程序改错题#include #include #define MAXLINE 20fun ( char *pstr6) int i, j ; char *p ; for (i = 0 ; i 5 ; i+ ) /*found*/参考答案:(1) for(j = i + 1; j 6; j+) (2) *(pstr + i) =*( pstr + j); for (j = i + 1, j 0) p = *(pstr + i) ;/*found*/ *(pstr + i) = pstr + j ; *(pstr + j) = p ; 三、程序编写题 (对应题库53套编程题特殊方法练习)第13套题一、程序填空题#include void fun(char *s) int i, j, n; for(i=0; si!=0; i+)/*found*/ if(si=0 _1_ sii; j-)/*found*/ sj+1= _3_; sj+1=*; i=i+1; 二、程序改错题#include double fun ( int m )参考答案:(1)for(i=2;i=m;i+)(2) y+=1.0/(i*i); double y = 1.0 ; int i;/*found*/ for(i = 2 ; i m ; i+)/*found*/ y += 1 / (i * i) ; return( y ) ;三、程序编写题 (对应题库81套编程题特殊方法练习)第14套题一、程序填空题#include void fun(char *s, int *t) int i, n; n=0;参考答案:(1)si (2)9(3) *t=n;/*found*/ for(i=0; _1_ !=0; i+)/*found*/ if(si=0&si= _2_ ) n+;/*found*/ _3_ ;二、程序改错题#include 参考答案:(1) t=*x;*x=y; (2) return (t);int fun(int *x,int y) int t ;/*found*/ t = x ; x = y ;/*found*/ return(y) ;三、程序编写题 (对应题库67套编程题记程序 背答案)第15套题一、程序填空题#include void fun(char *s) int i, n, k; char c; n=0; for(i=0; si!=0; i+) n+;/*found*/参考答案:(1) 1 (2) sk (3) c if(n%2=0) k=n-_1_ ; else k=n-2;/*found*/ c=_2_ ; for(i=k-2; i=1; i=i-2) si+2=si;/*found*/ s1=_3_ ;二、程序改错题#include 参考答案:(1) long s = 0,t = 0; (2) t = t / 10;long fun (int a, int n) int j ;/*found*/ long s = 0, t = 1 ; for ( j = 0 ; j n ; j+) t = t * 10 + a ; s = t ; for ( j = 1 ; j n ; j+) /*found*/ t = t % 10 ; s = s - t ; return(s) ;三、程序编写题 (对应题库74套编程题特殊方法练习)第16套题一、程序填空题#include void fun(char *s, char *p) int i, j, n, x, t; n=0; for(i=0; si!=0; i+) n+;参考答案:(1) t=i (2) i (3) 0 for(i=1; in-2; i=i+2) /*found*/ _1_;/*found*/ for(j=_2_+2 ; jsj) t=j; if(t!=i) x=si; si=st; st=x; for(i=1,j=0; in; i=i+2, j+) pj=si;/*found*/ pj=_3_;二、程序改错题#include #include float fun ( float num )参考答案:(1)while(fabs(t)=num) (2) t=s/n; int s ; float n, t, pi ; t = 1 ; pi = 0 ; n = 1 ; s = 1 ;/*found*/ while(t = num) pi = pi + t ; n = n + 2 ; s = -s ;/*found*/ t = s % n ; pi = pi * 4 ; return pi ;三、程序编写题 (对应题库55套编程题特殊方法练习)第17套题一、程序填空题#include void fun(char *s, char c) int i, j, n;/*found*/ for(i=0; si!=_1_ ; i+)参考答案:(1) 0或0 (2) 0 (3) c if(si=c) /*found*/ n=_2_ ; while(si+1+n!=0) n+; for(j=i+n+1; ji; j-) sj+1=sj;/*found*/ sj+1=_3_ ; i=i+1; 二、程序改错题#include double fun ( int x)参考答案:(1) double sum=0.0; (2) sum/=c;/*found*/ int sum = 0.0; int c=0, i=0; while (xi != 0) if (xi 0) sum += xi; c+; i+; /*found*/ sum = c; return sum;三、程序编写题 (对应题库91套编程题背答案)第18套题一、程序填空题#include #define N 4void fun(int (*t)N, int m) int i, j;参考答案:(1) i+ (2) m (3) m /*found*/ for(i=0; i=0; j-)/*found*/ tij+_2_ =tij;/*found*/ for(j=0; j_3_; j+) tij=0; 二、程序改错题#include #include int fun( int high ) int sum = 0, n=0, j, yes;/*found*/ while (high = 2) & (n =2)&(n10) (2) 缺分号 yes = 1; for (j=2; j=high/2; j+ ) if (high % j =0 )/*found*/ yes=0; break if (yes) sum +=high; n+; high-; return sum ;三、程序编写题 (对应题库70套编程题背答案)第19套题一、程序填空题#include #define N 4参考答案:(1)N (2)N-1 (3)0void fun(int (*t)N) int i, j, x;/*found*/ for(i=0; i=1; j-) tij=tij-1;/*found*/ ti_3_=x; 二、程序改错题#include double fun( double q ) int n; double s,t; n = 2; s = 2.0; while (s=q) t=s;参考答案:(1)s=s+(n+1.0)/n; (2)return t;/*found*/ s=s+(n+1)/n; n+; printf(n=%dn,n);/*found*/ return s;三、程序编写题 (对应题库76套编程题背答案)第20套题一、程序填空题#include #define N 4void fun(int (*t)N)参考答案:(1)0 (2)j- (3)j int j ,rN; for(j=0; jN; j+) rj=t0j; for(j=0; jN; j+)/*found*/ t0N-j-1=tj_1_ ; for(j=0; j=0;_2_ ) tN-1N-1-j=tjN-1; for(j=N-1; j=0; j-)/*found*/ tjN-1=r_3_;二、程序改错题#include #include /*found*/f( double x) if (x = 0.0 | x = 2.0) return 0.0;参考答案:(1)double f(double x)(2)缺分号 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; for (i= -n; i=n; i+) y=f(1.0*i); s += y;/*found*/ return s三、程序编写题 (对应题库89套编程题背答案)第21套题一、程序填空题#include int fun(int x) int n, s1, s2, s3, t;参考答案:(1) 0 (2) x (3) t+ /*found*/ n=_1_; t=100;/*found*/ while(t=_2_) s1=t%10; s2=(t/10)%10; s3=t/100; if(s1+s2+s3=15) printf(%d ,t); n+; /*found*/ _3_; return n;二、程序改错题#include #include void fun (char *s, char *t)参考答案:(1) int i,s1; (2) ti=ss1-1-i; /*found*/ int i; sl = strlen(s); for (i=0; isl; i+)/*found*/ ti = ssl-i; for (i=0; isl; i+) tsl+i = si; t2*

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论