[电脑基础知识]C语言上机题库及解析.doc
《[电脑基础知识]C语言上机题库及解析.doc》由会员分享,可在线阅读,更多相关《[电脑基础知识]C语言上机题库及解析.doc(390页珍藏版)》请在三一文库上搜索。
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_); fcl
2、ose(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(nRead
3、 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);答案:1.STYPE 2.FILE 3.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
4、 (i=0; isl; i+)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);答案:1.for(i=0;is1;i+) 2.t2*s1=0三、编程#include void fun(int a, int b, long *c)main() int a,b; long c; void NONO ( ); printf(Input a, b:); scanf
5、(%d,%d, &a, &b); fun(a, b, &c); printf(The result is: %dn, c); NONO();void NONO ( )/* */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(C:WEXAM24990001in.dat, r) ; wf = fopen(C:WEXAM24990001out.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
6、, a, b, c) ; fclose(rf) ; fclose(wf) ;答案:#include void fun(int a, int b, long *c) *c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10);main() int a,b; long c; printf(Input a, b:); scanf(%d,%d, &a, &b); fun(a, b, &c); printf(The result is: %dn, c); NONO();NONO ( )/* */ FILE *rf, *wf ; int i, a,b ; long c ; rf
7、= fopen(C:WEXAM24990001in.dat, r) ; wf = fopen(C:WEXAM24990001out.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) ; fclose(rf) ; fclose(wf) ;第二套一、填空#include #include #include void WriteText(FILE *);void ReadText(FILE *);main() FILE *
8、fp; if(fp=fopen(myfile4.txt,w)=NULL) printf( open fail!n); exit(0); WriteText(fp); fclose(fp); if(fp=fopen(myfile4.txt,r)=NULL) printf( open fail!n); exit(0); ReadText(fp); fclose(fp);/*found*/void WriteText(FILE _1_) char str81; printf(nEnter string with -1 to end :n); gets(str); while(strcmp(str,-
9、1)!=0) /*found*/ fputs(_2_,fw); fputs(n,fw); gets(str); void ReadText(FILE *fr) char str81; printf(nRead file and output to screen :n); fgets(str,81,fr); while( !feof(fr) ) /*found*/ printf(%s,_3_); fgets(str,81,fr); 答案:1.*fw 2.str 3.str二、改错#include /*found*/void fun (long s, long t) long sl=10; *t
10、= 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);答案:1.void fun(long s,long *t) 2.s1=s1*10;三、编程#include void fun(int a, int b, long *c)main() int a,b; long c; void NONO (
11、); printf(Input a, b:); scanf(%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(C:WEXAM24990001in.dat, r) ; wf = fopen(C:WEXAM24990001out.dat,w) ; for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, &a, &b) ; fun(a, b, &c)
12、; fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c) ; fclose(rf) ; fclose(wf) ;答案:#include void fun(int a, int b, long *c) *c=(b/10)*1000+(a%10)*100+(b%10)*10+(a/10);main() int a,b; long c; printf(Input a, b:); scanf(%d,%d, &a, &b); fun(a, b, &c); printf(The result is: %ldn, c); NONO();NONO ( )/* */ FILE *rf,
13、*wf ; int i, a,b ; long c ; rf = fopen(C:WEXAM24990001in.dat, r) ; wf = fopen(C:WEXAM24990001out.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) ; fclose(rf) ; fclose(wf) ;第三套一、填空#include #include int fun(char *fname ) FILE *fp; int
14、i,n; float x; if(fp=fopen(fname, w)=NULL) return 0; for(i=1;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,
15、&x); fclose(fp); return 1;main() char fname=myfile3.txt; fun(fname);答案:1.fp 2.fclose(fp) 3.fname二、改错#include #include 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; putarr( int n, int *z ) int i; fo
16、r ( i = 1; i = n; i+, z+ ) printf( %4d, *z ); if ( !( i%10 ) ) printf( n ); 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 );答案:1.for(i=j+1;in;i+) 2.p=i;三、编程#in
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电脑基础知识 电脑 基础知识 语言 上机 题库 解析
链接地址:https://www.31doc.com/p-1987445.html