程序设计35464.doc

上传人:汽*** 文档编号:557537305 上传时间:2023-09-04 格式:DOC 页数:71 大小:1.81MB
返回 下载 相关 举报
程序设计35464.doc_第1页
第1页 / 共71页
程序设计35464.doc_第2页
第2页 / 共71页
程序设计35464.doc_第3页
第3页 / 共71页
程序设计35464.doc_第4页
第4页 / 共71页
程序设计35464.doc_第5页
第5页 / 共71页
点击查看更多>>
资源描述

《程序设计35464.doc》由会员分享,可在线阅读,更多相关《程序设计35464.doc(71页珍藏版)》请在金锄头文库上搜索。

1、#include #include #define N 5typedef struct int num; char name10; char tel10;STYPE;void check();填空答案:(1)STYPE (2)FILE (3)fp/*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(

2、STYPE), 1, _3_); 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=s1; i +) ti = si; for (i=0; isl; i+)tsl+i = ssl-i-1;/*found*/ tsl = 0;三、程序编写题 (对应题库88套编程题-特殊方法练习)第2

3、套题一、程序填空题/*found*/void WriteText(FILE _1_) 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(_2_,fw); fputs(n,fw); gets(str); void ReadText(FILE *fr) char str81; printf(nRead file and output to screen :n); fgets(str,8

4、1,fr); while( !feof(fr) ) /*found*/ printf(%s,_3_); 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*/sl = sl*100; 三、程序编写题 (对应教材33题特殊方法练习)第3套题一、程序填空题#include

5、 #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) retu

6、rn 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

7、; 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*/ whil

8、e(!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; 三、程序编写题

9、 (对应题库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

10、-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-ne

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号