

下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、等级考试上机题目(上课用) 第1套 1程序填空: #include stdio.h #include stdlib.h #define n 5 typedef 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*/
2、 fwrite(stdi, sizeof(stype), 1, _3_); 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() 1 file *fp; int i; stype s10; if(fp=fopen(myfile5.dat,rb
3、)=null) printf(fail !n); exit(0); printf(nread 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.tel); fclose(fp); 2改错题 #include stdio.h #include string.h void fun (char *s, char *t) int i, sl; sl = strlen(s);
4、 /*found*/ for(i=0; i=s1; i +) ti = si; for (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); 2 3程序设计题 #include stdio.h void fun(int a, int b, long *c) main() int a,b; long c; void nono
5、(); printf(input a, b:); scanf(%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(in.dat, r); wf = fopen(out.dat,w); for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%d, a, b); fun(a, b, c); fprintf
6、(wf, a=%d,b=%d,c=%ldn, a, b, c); fclose(rf); fclose(wf); 3 第2套题 1程序填空题 #include stdio.h #include string.h #include stdlib.h 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.t
7、xt,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,-1)!=0) /*found*/ fputs(_2_,fw); fputs(n,fw); gets(str); void readtext(file *fr) char str81; printf(nread file and
8、output to screen :n); fgets(str,81,fr); while(!feof(fr) /*found*/ printf(%s,_3_); fgets(str,81,fr); 4 2程序修改题 #include stdio.h /*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:); sc
9、anf(%ld, s); fun(s, t); printf(the result is: %ldn, t); 3程序设计题 #include stdio.h void fun(int a, int b, long *c) 5 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 () /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ file
10、 *rf, *wf ; int i, a,b ; long c ; rf = fopen(in.dat, r); wf = fopen(out.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); 第3套 1程序填空题 #include math.h #include stdio.h int fun(char *fname) file *fp; int i,n; float x; i
11、f(fp=fopen(fname, w)=null) return 0; 6 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,x); fclose(
12、fp); return 1; main() char fname=myfile3.txt; fun(fname); 2程序填空题 #include stdio.h #include stdlib.h fun (int n, int *a) int i, j, p, t; for (j = 0; jn-1 ; j+) p = j; /*found*/ for (i=j+1; in-1 ; i+) if (apai) /*found*/ t=i; if (p!=j) t = aj; aj = ap; ap = t; putarr(int n, int *z) int i; for (i = 1;
13、i = n; i+, z+) 7 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); 3程序设计题 #include stdio.h void fun(int a, int b, long *c) main()
14、 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 () /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ file *rf, *wf ; int i, a,b ; long c ; 8 rf = fopen(in.dat, r); wf = fopen(out.dat,w); for(i = 0 ; i 10 ; i+) fscanf(rf, %d,%
15、d, a, b); fun(a, b, c); fprintf(wf, a=%d,b=%d,c=%ldn, a, b, c); fclose(rf); fclose(wf); 第4套 1程序填空题 #include stdio.h #include stdlib.h 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
16、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; main() 9 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
17、+rand()%25;fprintf(myf, %c,c); printf(%c,c); fclose(myf);printf(nn); if (fun(sfname, tfname) ) printf(succeed!); else printf(fail!); 2程序改错题 #include stdio.h 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(
18、) long s, t; printf(nplease enter s:); scanf(%ld, s); fun(s, t); printf(the result is: %ldn, t); 3程序设计题 10 #include stdio.h 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 (
19、) /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ file *rf, *wf ; int i, a,b ; long c ; rf = fopen(in.dat, r); wf = fopen(out.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); 11 第5套 1程序填空题 #include stdio.h #include stdlib.h #de
20、fine 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 xp-data) /*found*/ q=_2_; p=p-next; s-next=p; /*found*/ q-next=_3_; slist *creatlist(int *a) slist *h,*p,*q
21、; int i; h=p=(slist *)malloc(sizeof(slist); for(i=0; in; i+) q=(slist *)malloc(sizeof(slist); q-data=ai; p-next=q; p=q; p-next=0; return h; void outlist(slist *h) slist *p; 12 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); prin
22、tf(-endn); main() slist *head; int x; int an=11,12,15,18,19,22,25,29; head=creatlist(a); printf(nthe list before inserting:n); outlist(head); printf(nenter a number : ); scanf(%d,x); fun(head,x); printf(nthe list after inserting:n); outlist(head); 2程序改错题 #include stdio.h long fun (long num) /*found*
23、/ long k; do k*=num%10 ; /*found*/ num=10 ; while(num); return (k); main() long n ; printf(nplease enter a number:); scanf(%ld,n); printf(n%ldn,fun(n); 3程序设计题 13 #include stdio.h float fun (float *a , int n) main() float score30=90.5, 72, 80, 61.5, 55, aver; void nono (); aver = fun(score, 5); print
24、f(naverage score is: %5.2fn, aver); nono (); void nono () /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ file *fp, *wf ; int i, j ; float aver, score5 ; fp = fopen(in.dat,r); wf = fopen(out.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
25、); fclose(fp); fclose(wf); 14 第6套 1程序填空题 #include stdio.h #include stdlib.h #define n 8 typedef 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*/ t=t-_1_; /*found*/ printf( %d ,_2_); s-next=null; /*found*/ free(_3_);
26、slist *creatlist(int *a) slist *h,*p,*q; int i; h=p=(slist *)malloc(sizeof(slist); for(i=0; in; i+) q=(slist *)malloc(sizeof(slist); q-data=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); 15 else printf(nhead); do printf(-%d,
27、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); printf(noutput from tail: n); while (head-next != null) fun(head); printf(nn); printf(noutput from head again :n); outlist(head); 2程序改错
28、题 #include stdio.h /*found*/ fun (char a) if (*a) fun(a+1); /*found*/ printf(%c *a); main() char s10=abcd; printf(处理前字符串=%sn处理后字符串=, s); fun(s); printf(n); 3程序设计题 16 #include stdio.h char *fun (char *s, char *t) main() char a20,b20; void nono (); printf(input 1th string:); gets(a); printf(input 2th
29、string:); gets(b); printf(%sn,fun (a, b); nono (); void nono () /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ file *fp, *wf ; int i ; char a20, b20 ; fp = fopen(in.dat,r); wf = fopen(out.dat,w); for(i = 0 ; i 10 ; i+) fscanf(fp, %s %s, a, b); fprintf(wf, %sn, fun(a, b); fclose(fp); fclose(wf); 17 第7套 1程序填空题 #
30、include stdio.h #include stdlib.h #define n 8 typedef struct list int data; struct list *next; slist; 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*/ q=p-_2_; else p=q; /*found*/ q=q-_3_; slist *creatli
31、st(int *a) slist *h,*p,*q; int i; h=p=(slist *)malloc(sizeof(slist); for(i=0; in; i+) q=(slist *)malloc(sizeof(slist); q-data=ai; p-next=q; p=q; 18 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-n
32、ext; 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); 2程序修改题 #include stdio.h #define n 20 void fun(int a, int n) int i, j, t, p; for (j = 0 ;j n-1 ;j+) /*found*/ p = j for (i = j;i n; i+) if(ai ap)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030中国原声钢琴行业产业运行态势及投资规划深度研究报告
- 2025至2030中国医用手榴弹泵行业产业运行态势及投资规划深度研究报告
- 2025至2030中国助行架和助行车行业产业运行态势及投资规划深度研究报告
- 北大环境监测课件07噪声污染监测
- 无锡市文物考古研究所招聘笔试真题2024
- 杭州市留下小学招聘各科教师笔试真题2024
- 城市体育公园场地租赁管理合同
- 榆林神木市第五幼儿园招聘考试真题2024
- 高端制造业博览会参展商权益保障合同汇编
- 茶文化体验中心茶艺服务合作协议
- 艾梅乙反歧视培训课件
- 浙江省杭州市2024-2025学年高二下学期6月期末教学质量检测英语试题(含答案)
- 2025年河南省中考地理试题(含答案)
- 2025安全生产月一把手讲安全公开课三十二(91P)
- DB64-266-2018 建筑工程资料管理规程
- 人教鄂教版六年级下册科学期末专题训练:实验题、综合题(含答案)
- 2025年经济法与金融监管专业考试试题及答案
- 基于项目式学习的小学劳动教育课程教学设计
- 2025届湖北省武汉市武昌区南湖中学英语七年级第二学期期末达标检测试题含答案
- 等离子体泡跨尺度耦合-洞察及研究
- 2025课件:红色基因作风建设七一党课
评论
0/150
提交评论