2011年9月二级C语言题库及参考答案

上传人:hjk****65 文档编号:220785958 上传时间:2023-07-02 格式:DOC 页数:163 大小:1.82MB
收藏 版权申诉 举报 下载
2011年9月二级C语言题库及参考答案_第1页
第1页 / 共163页
2011年9月二级C语言题库及参考答案_第2页
第2页 / 共163页
2011年9月二级C语言题库及参考答案_第3页
第3页 / 共163页
资源描述:

《2011年9月二级C语言题库及参考答案》由会员分享,可在线阅读,更多相关《2011年9月二级C语言题库及参考答案(163页珍藏版)》请在装配图网上搜索。

1、第1套题一、程序填空题#include #include #define N 5typedef struct int num; char name10; char tel10;STYPE;void check();/*found*/int fun(_1_ *std)/*found*/ _2_ *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, _3_);

2、 fclose(fp); return (1);main() STYPE s10= 1,aaaaa,111111,1,bbbbb,222222,1,ccccc,333333, 1,ddddd,444444,1,eeeee,555555; int k; k=fun(s); if (k=1) printf(Succeed!); check(); else printf(Fail!);void check() FILE *fp; int i; STYPE s10; if(fp=fopen(myfile5.dat,rb)=NULL) printf(Fail !n); exit(0); printf(n

3、Read file and output to screen :n); printf(n num name teln); for(i=0; iN; i+) fread(&si,sizeof(STYPE),1, fp); printf(%6d %s %sn,si.num,si.name,si.tel); fclose(fp);二、程序改错题#include #include void fun (char *s, char *t) int i, sl; sl = strlen(s);/*found*/ for( i=0; i=s1; i +) ti = si; for (i=0; isl; i+)

4、tsl+i = ssl-i-1;/*found*/ tsl = 0;main() char s100, t100; printf(nPlease enter string s:); scanf(%s, s); fun(s, t); printf(The result is: %sn, t);三、程序编写题#include void fun(int a, int b, long *c)main() int a,b; long c; void NONO ( ); printf(Input a b:); scanf(%d%d, &a, &b); fun(a, b, &c); printf(The r

5、esult is: %dn, c); NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(K:k0124010001in.dat, r) ; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, &a, &b) ; fun(a, b, &c) ; fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c) ; fclo

6、se(rf) ; fclose(wf) ;第2套题一、程序填空题#include #include #include void WriteText(FILE *);void ReadText(FILE *);main() FILE *fp; if(fp=fopen(myfile4.txt,w)=NULL) printf( open fail!n); exit(0); WriteText(fp); fclose(fp); if(fp=fopen(myfile4.txt,r)=NULL) printf( open fail!n); exit(0); ReadText(fp); fclose(fp)

7、;/*found*/void WriteText(FILE _1_) char str81; printf(nEnter string with -1 to end :n); gets(str); while(strcmp(str,-1)!=0) /*found*/ fputs(_2_,fw); fputs(n,fw); gets(str); void ReadText(FILE *fr) char str81; printf(nRead file and output to screen :n); fgets(str,81,fr); while( !feof(fr) ) /*found*/

8、printf(%s,_3_); fgets(str,81,fr); 二、程序改错题#include /*found*/void fun (long s, long t) long sl=10; *t = s % 10; while ( s 0) s = s/100; *t = s%10 * sl + *t;/*found*/sl = sl*100; main() long s, t; printf(nPlease enter s:); scanf(%ld, &s); fun(s, &t); printf(The result is: %ldn, t);三、程序编写题#include #defi

9、ne N 16typedef struct char num10; int s; STREC;int fun( STREC *a, STREC *b )main() STREC sN=GA05,85,GA03,76,GA02,69,GA04,85,GA01,91,GA07,72,GA08,64,GA06,87,GA015,85,GA013,91,GA012,64,GA014,91,GA011,91,GA017,64,GA018,64,GA016,72; STREC hN; int i,n;FILE *out ; n=fun( s,h ); printf(The %d lowest score

10、:n,n); for(i=0;in; i+) printf(%s %4dn,hi.num,hi.s); printf(n); out = fopen(K:k0124010001out.dat,w) ; fprintf(out, %dn,n); for(i=0;in; i+) fprintf(out, %4dn,hi.s); fclose(out);第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;

11、i=10;i+)/*found*/ 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;main() char fname=myfile3.txt; fu

12、n(fname);二、程序改错题#include #include void fun ( int n, int *a ) int i, j, p, t; for ( j = 0; jn-1 ; j+ ) p = j;/*found*/ for ( i=j+1; iai )/*found*/ t=i; if ( p!=j ) t = aj; aj = ap; ap = t; void putarr( int n, int *z ) int i; for ( i = 1; i = n; i+, z+ ) printf( %4d, *z ); if ( !( i%10 ) ) printf( n )

13、; printf(n);main() int aa20=9,3,0,4,1,2,5,6,8,10,7, n=11; printf( nnBefore sorting %d numbers:n, n ); putarr( n, aa ); fun( n, aa ); printf( nAfter sorting %d numbers:n, n ); putarr( n, aa );三、程序编写题#include void fun(int a, int b, long *c)main() int a,b; long c; void NONO ( ); printf(Input a b:); sca

14、nf(%d%d, &a, &b); fun(a, b, &c); printf(The result is: %ldn, c); NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(K:k0124010001in.dat, r) ; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, &a, &b) ; fun(a, b, &c) ;

15、 fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c) ; fclose(rf) ; fclose(wf) ;第4套题一、程序填空题#include #include int fun(char *source, char *target) FILE *fs,*ft; char ch;/*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*/ whi

16、le(!feof(_2_) putchar( ch );/*found*/ fputc(ch,_3_); ch=fgetc(fs); fclose(fs); fclose(ft); printf(nn); return 1;main() char sfname20 =myfile1,tfname20=myfile2; FILE *myf; int i; char c; myf=fopen(sfname,w); printf(nThe original data :n); for(i=1; i30; i+) c=A+rand()%25;fprintf(myf,%c,c); printf(%c,c

17、); fclose(myf);printf(nn); if (fun(sfname, tfname) printf(Succeed!); else printf(Fail!);二、程序改错题#include void fun (long s, long *t) int d; long sl=1; *t = 0; while ( s 0) d = s%10;/*found*/ if (d%2=0) *t=d* sl+ *t; sl *= 10; /*found*/ s = 10; main() long s, t; printf(nPlease enter s:); scanf(%ld, &s)

18、; fun(s, &t); printf(The result is: %ldn, t);三、程序编写题#include #include void fun(char *s, char t)main() char s100, t100; void NONO ( ); printf(nPlease enter string S:); scanf(%s, s); fun(s, t); printf(nThe result is: %sn, t); NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ char s100, t100 ; F

19、ILE *rf, *wf ; int i ; rf = fopen(K:k0124010001in.dat,r) ; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %s, s) ; fun(s, t) ; fprintf(wf, %sn, t) ; fclose(rf) ; fclose(wf) ;第5套题一、程序填空题#include #include #define N 8typedef struct list int data; struct list *next; SLIST;void fu

20、n( SLIST *h, int x) SLIST *p, *q, *s; s=(SLIST *)malloc(sizeof(SLIST);/*found*/ s-data=_1_; q=h; p=h-next; while(p!=NULL & xp-data) /*found*/ q=_2_; p=p-next; s-next=p;/*found*/ q-next=_3_;SLIST *creatlist(int *a) SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; idata=ai; p-next=q;

21、 p=q; p-next=0; return h;void outlist(SLIST *h) SLIST *p; p=h-next; if (p=NULL) printf(nThe list is NULL!n); else printf(nHead); do printf(-%d,p-data); p=p-next; while(p!=NULL); printf(-Endn); main() SLIST *head; int x; int aN=11,12,15,18,19,22,25,29; head=creatlist(a); printf(nThe list before inser

22、ting:n); outlist(head); printf(nEnter a number : ); scanf(%d,&x); fun(head,x); printf(nThe list after inserting:n); outlist(head);二、程序改错题#include long fun (long num)/*found*/ long k; do k*=num%10 ;/*found*/ num=10 ; while(num) ; return (k) ;main( ) long n ; printf(nPlease enter a number:) ; scanf(%l

23、d,&n) ; printf(n%ldn,fun(n) ;三、程序编写题#include float fun ( float *a , int n )main() float score30=90.5, 72, 80, 61.5, 55, aver; void NONO ( ); aver = fun( score, 5 ); printf( nAverage score is: %5.2fn, aver); NONO ( );void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, j ; float a

24、ver, score5 ; fp = fopen(K:k0124010001in.dat,r) ; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) for(j = 0 ; j 5 ; j+) fscanf(fp,%f,&scorej) ; aver = fun(score, 5) ; fprintf(wf, %5.2fn, aver) ; fclose(fp) ; fclose(wf) ;第6套题一、程序填空题#include #include #define N 8typedef struct list int data

25、; struct list *next; SLIST;void fun( SLIST *p) SLIST *t, *s; t=p-next; s=p; while(t-next != NULL) s=t;/*found*/ t=t-_1_; /*found*/ printf( %d ,_2_); 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; idata=ai; p-next=q; p=q; p-

26、next=0; return h;void outlist(SLIST *h) SLIST *p; p=h-next; if (p=NULL) printf(nThe list is NULL!n); else printf(nHead); do printf(-%d,p-data); p=p-next; while(p!=NULL); printf(-Endn); main() SLIST *head; int aN=11,12,15,18,19,22,25,29; head=creatlist(a); printf(nOutput from head:n); outlist(head);

27、printf(nOutput from tail: n); while (head-next != NULL) fun(head); printf(nn); printf(nOutput from head again :n); outlist(head); 二、程序改错题#include /*found*/fun (char a) if ( *a ) fun(a+1) ;/*found*/ printf(%c *a) ; main( ) char s10=abcd; printf(处理前字符串=%sn处理后字符串=, s); fun(s); printf(n) ;三、程序编写题#includ

28、e char *fun ( char *s, char *t)main( ) char a20,b20; void NONO ( ); printf(Input 1th string:) ; gets( a); printf(Input 2th string:) ; gets( b); printf(%sn,fun (a, b ); NONO ();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i ; char a20, b20 ; fp = fopen(K:k0124010001in.dat,r)

29、; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(fp, %s %s, a, b) ; fprintf(wf, %sn, fun(a, b) ; fclose(fp) ; fclose(wf) ;第7套题一、程序填空题#include #include #define N 8typedef struct list int data; struct list *next; SLIST;void fun( SLIST *h) SLIST *p, *q; p=h-next; if (p!=NULL) q=p-ne

30、xt; while(q!=NULL) if (p-data=q-data) p-next=q-next;/*found*/ free(_1_);/*found*/ q=p-_2_; else p=q;/*found*/ q=q-_3_; SLIST *creatlist(int *a) SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; idata=ai; p-next=q; p=q; p-next=0; return h;void outlist(SLIST *h) SLIST *p; p=h-next; if

31、 (p=NULL) printf(nThe list is NULL!n); else printf(nHead); do printf(-%d,p-data); p=p-next; while(p!=NULL); printf(-Endn); main( ) SLIST *head; int aN=1,2,2,3,4,4,4,5; head=creatlist(a); printf(nThe list before deleting :n); outlist(head); fun(head); printf(nThe list after deleting :n); outlist(head

32、);二、程序改错题#include #define N 20void fun(int a, int n) int i, j, t, p; for (j = 0 ;j n-1 ;j+) /*found*/ p = j for (i = j+1;i n; i+) if(ai ap)/*found*/ p = j; t = ap ; ap = aj ; aj = t; main() int aN=9,6,8,3,-1,i, m = 5; printf(排序前的数据:) ; for(i = 0;i m;i+) printf(%d ,ai); printf(n); fun(a,m); printf(排序

33、后的数据:) ; for(i = 0;i m;i+) printf(%d ,ai); printf(n);三、程序编写题#include #define M 100void fun ( int m, int *a , int *n )main( ) int aaM, n, k; void NONO ( ); fun ( 50, aa, &n ); for ( k = 0; k n; k+ ) if(k+1)%20=0) printf(n); else printf( %4d, aak ); printf(n) ; NONO( );void NONO ( )/* 本函数用于打开文件,输入数据,调

34、用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; int i, n, j, k, aaM, sum ; fp = fopen(K:k0124010001in.dat,r) ; wf = fopen(K:k0124010001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(fp, %d, &j) ; fun(j, aa, &n) ; sum = 0 ; for(k = 0 ; k n ; k+) sum+=aak ; fprintf(wf, %dn, sum) ; fclose(fp) ; fclose(wf) ;第8套题一、程序填空题#i

35、nclude #include #define N 8typedef struct list int data; struct list *next; SLIST;SLIST *creatlist(char *);void outlist(SLIST *);int fun( SLIST *h, char ch) SLIST *p; int n=0; p=h-next;/*found*/ while(p!=_1_) n+;/*found*/ if (p-data=ch) return _2_; else p=p-next; return 0;main() SLIST *head; int k;

36、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);SLIST *creatlist(char *a) SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; ida

37、ta=ai; p-next=q; p=q; p-next=0; return h;void outlist(SLIST *h) SLIST *p; p=h-next; if (p=NULL) printf(nThe list is NULL!n); else printf(nHead); do printf(-%c,p-data); p=p-next; while(p!=NULL); printf(-Endn); 二、程序改错题#include #include #include fun ( char *p) int i,t; char c80;/*found*/ For (i = 0,t =

38、 0; pi ; i+) if(!isspace(*(p+i) ct+=pi;/*found*/ ct=0; strcpy(p,c);main( ) char c,s80; int i=0; printf(Input a string:); c=getchar(); while(c!=#) si=c;i+;c=getchar(); si=0; fun(s); puts(s);三、程序编写题#include #include void fun ( char *ss )main( ) char tt81 ; void NONO ( ); printf( nPlease enter an strin

39、g within 80 characters:n ); gets( tt ); printf( nnAfter changing, the stringn %s, tt ); fun( tt ); printf( nbecomesn %sn, tt ); NONO ( );void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf ; char tt81 ; int i ; fp = fopen(K:k0124010001in.dat,r) ; wf = fopen(K:k0124010001out.dat,w) ; for(

40、i = 0 ; i 10 ; i+) fscanf(fp, %s, tt) ; fun( tt ) ; fprintf(wf, %sn, tt) ; fclose(fp) ; fclose(wf) ;第9套题一、程序填空题#include #include #define N 8typedef struct list int data; struct list *next; SLIST;SLIST *creatlist(int *a);void outlist(SLIST *);void fun( SLIST *h, int *n) SLIST *p;/*found*/ _1_=0; p=h-

41、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);SLIST *creatlist(int a) SLIST *h,*p,*q; int i; h=p=(SLIST *)malloc(sizeof(SLIST); for(i=0; idata=ai; p-next=q; p=q; p-ne

42、xt=0; return h;void outlist(SLIST *h) SLIST *p; p=h-next; if (p=NULL) printf(The list is NULL!n); else printf(nHead ); do printf(-%d,p-data); p=p-next; while(p!=NULL); printf(-Endn); 二、程序改错题#include #include char * fun (char *s, char *t ) char *p , *r, *a;/*found*/ a = Null; while ( *s ) p = s; r =

43、t; while ( *r )/*found*/ if ( r = p ) r+; p+; else break; if ( *r = 0 ) a = s; s+; return a ;main() char s100, t100, *p; printf(nPlease enter string S :); scanf(%s, s ); printf(nPlease enter substring t :); scanf(%s, t ); p = fun( s, t ); if ( p ) printf(nThe result is : %sn, p); else printf(nNot found !n );三、程序编写题#include void fun(int a, int b, long *c)main() int a,b; long c; void NONO ( ); printf(Input a b:); scanf(%d%d, &a, &b); fun(a, b, &c); printf(The result is: %ldn, c); NONO();void NONO ( )/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!