ImageVerifierCode 换一换
格式:DOCX , 页数:33 ,大小:31.78KB ,
资源ID:4657236      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4657236.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(第1部分 程序改错题.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

第1部分 程序改错题.docx

1、第1部分 程序改错题第1部分 程序改错题第1题在主函数中从键盘输入若干个数放入数组中,输入0结束输入并放在最后一个元素中。给定程序MODI0.C中函数fun的功能是:计算数组中值为正数的平均值(不包括0)。例如:数组中元素的值依次为:39,-47,21,2,-8,15,0,则程序的运行结果为:19.25。请改正函数fun中的错误,使它能输出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include double fun (int x) int sum=0.0; int c=0,i=0; while(xi!=0) if (xi0) sum+=

2、xi; c+ i+; sum=c; return sum;main() int x1000; int i=0; clrscr(); printf(nPlease enter some data (end with 0):); do scanf(%d,&xi); while (xi+!=0); printf(%fn,fun(x);第2题学生花名册可以用结构体型链表存放。结构中包含成员学号(int xh)、姓名(char xm8)、性别(char sex)、班级号(int bj)、成绩(int cj),sex=m表示男学生,w为女学生,班级序号bj为1至9。该结构已用typedef定义为数据类型S

3、TUDENT。给定程序FILL0.C就建立了这样一个链表,函数ftotal()的功能是:统计各班的平均成绩。请改正函数ftotal中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include typedef struct STUDENT long xh; char xm8; char sex; int bj; int cj; struct STUDENT * next;void ftotal(struct STUDENT *head,int a) struct STUDENT * p; int b9,i; p=head;

4、 for(i=0;ibj-1=p-cj; bp-bj-1=1; p=p-next; for(i=0;ibj,p-xm); scanf(%d,&p-cj); p=p-next; struct STUDENT * fsetup() struct STUDENT *h,*p,*p1; h=NULL; p1=NULL; while(1) p=(struct STUDENT * )malloc (sizeof(struct STUDENT); scanf(%ld %s %c %d,&p-xh,p-xm,&p-sex,&p-bj); p-cj=0; if (p-xh=0) free(p); if (p1)

5、 p1-next=NULL; break; else if(h=0)h=p;p1=p; else p1-next=p;p1=p; return h;print(struct STUDENT * head) struct STUDENT * p; p=head; while(p) printf(%08ld,%-8s,%c,%1d,%3dn,p-xh,p-xm,p-sex,p-bj,p-cj); p=p-next; printf(n);main() struct STUDENT *h; int a9,i; h=fsetup(); print(h); finput(h); print(h); fto

6、tal(h,a); for (i=0;i9;i+) if (ai) printf(The score of class %d is %dn,i+1,ai);第3题给定程序MODI1.C中函数fun的功能是:求广义菲玻那级数的第n项。1,1,1,3,5,9,17,31,. 项值通过函数值返回main()函数。例如:若n=15,则应输出:2209。请改正函数fun中的语法错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include long fun(int n) long a=1,b=1,c=1,d=1,k; For (k=4;

7、k=n;k+) d=a+b+c; a=b;b=c;c=d return d;main() int n=15; clrscr(); printf(The value is %ldn,fun(n); NONO();NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件*/ FILE *rf,*wf; int i,n; rf=fopen(gc01.in,r); wf=fopen(gc01.out,w); for(i=0;i10;i+) fscanf(rf,%d,&n); fprintf(wf,%ldn,fun(n); fclose(rf); fclose(wf);第4题给定程序F

8、ILL1.C中函数scmp的功能是比较两个给出的C字符串。按比较结果,函数将返回如下函数值: 若: s1=s2 返回0 s1s2 返回正值请改正函数scmp中的语法和逻辑错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include#include#include#define N 40scmp(char * s1,char * s2) while(*s1) if(s1!=s2) return (*s1-*s2) ; else (*s1)+; s2+; return ( *s1 );main() char str1=china,str2=chi

9、ness,str3=china,str4=chinaren; printf(the result for compare %s and %s is %dn,str1,str2,scmp(str1,str2); printf(the result for compare %s and %s is %dn,str2,str3,scmp(str2,str3); printf(the result for compare %s and %s is %dn,str1,str3,scmp(str1,str3); printf(the result for compare %s and %s is %dn,

10、str3,str4,scmp(str3,str4); NONO(); NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件*/ FILE *rf,*wf; int i,n; char str1N,str2N; rf=fopen(tk01.in,r); wf=fopen(tk01.out,w); for(i=0;i3;i+) fscanf(rf,%s %s,&str1,&str2); fprintf(wf,%dn,scmp(str1,str2); fclose(rf); fclose(wf);第5题给定程序MODI2.C中函数fun的功能是:通过某种程度方式实现两个变量的值

11、交换的操作,例如变量a中的值原为8,b中的值原为3,程序运行后变量a中的值为3,b中的值原为8。请改正函数fun中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include int fun(int *x,int y) int t; t=x;x=y; return(y);main() int a=3,b=8; clrscr(); printf(%d %dn,a,b); b=fun(&a,b); printf(%d %dn,a,b);第6题给定程序FILL2.C中函数printd(int n)的功能是以十进制数形式打印出任i

12、nt型数。请改正函数printd中的语法和逻辑错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!下面函数的功能是以十进制数形式打印出任int型数。请填入适当语句完善之。#includestdio.hprintd(int n) int i; if(n0) n=-n; printf(+); if( i=n/10 !=0 ) printd(i); putchar( n + 0 );main() printd(12345); printf(n); printd(-32091); printf(n); printd(0); printf(n); printd

13、(-2); printf(n);第7题给定程序MODI3.C中函数fun的功能是:计算并输出k以内最大的10个能被13或17整除的自然数之和。k的值由主函数传入,若k的值为500,则函数值为4622。请改正函数fun中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include int fun(int k) int m=0,mc=0,j,n; while(k=2)&mc10) if (k%13=0)|(k%17=0) m=m+k;mc+; k-; return m;main() clrscr(); printf(%d n,

14、fun(500);第8题给定程序FILL3.C的程序建立一个链表,函数finsert(struct node *head,int x)的功能是:在链表头部插入一个结点,数据域的值为x,并返回新链表的头指针主函数。该函数的第一个参数是链表的首指针。请改正函数finsert中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!程序#include #include struct node int data; struct node * next;struct node * finsert(struct node *head,int x) struct

15、node * p; p=malloc (sizeof(struct node * ); p-data=x; p-next=head; return head;print(struct node * head) struct node * p; p=head; while(p) printf(%dn,p-data); p=p-next; printf(n);main() struct node *h =NULL, *p,*p1; int a,i; for(i=0;i10;i+) a=rand()%1000; h=finsert(h,a); print(h);第9题给定程序MODI4.C中函数fu

16、n的功能是:读入一个整数m,计算如下公式的值。 t = 1- 例如:若输入5,则应输出 -0.283333。 请改正函数fun中的错误,使它能计算出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include double fun(int m) double t=1.0; int i; for(i=2;i=m;i+) t=1.0-1/i; t;main() int m; clrscr(); printf(n Please enter 1 integer numbers:n); scanf( %d,&m); printf(n the resu

17、lt is %lfn,fun(m); NONO();NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件*/ FILE *rf,*wf; int j,n; rf=fopen(gc04.in,r); wf=fopen(gc04.out,w); for (j=1;j=10;j+) fscanf(rf,%d,&n); fprintf(wf, %lfn,fun(n); fclose(rf); fclose(wf);第10题给定程序FILL3.C的程序首先建立一个链表,函数fmax()的功能是:求出链表所有结点中,数据域值最大的结点的值,并由参数s返回给主函数。该函数的第一个参数是

18、链表的首指针。请改正函数fmax中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include struct node int data; struct node * next;void fmax(struct node *head,struct node * *s) struct node * p; p=head; *s=p; if(p) return; while(p=NULL) if(p-data s-data ) s=p; p=p-next; printf(n);print(struct node * head)

19、struct node * p; p=head; while(p) printf(%d,p-data); p=p-next; printf(n);main() struct node *h =0, *p,*p1; int a,i; for(i=0;idata=a; if(h=0)h=p;p1=p; else p1-next=p;p1=p; p-next=0 ; print(h); fmax(h,&p); print(h); if(p) printf(Max data is:%dn,p-data);第11题给定程序MODI5.C中函数fun的功能是:用于计算 S=f( (f(-1.0)+f(5.

20、0) 的值。当程序正确时,函数值应为:2488.00000。设请改正函数fun中的错误,使它能输出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include double fun(double x) double y; int i; If (x=2.0) y=2.0*x*x*+3.0*x+4.0; else y=-2.0*x*x+3.0*x-4.0; return ymain() clrscr(); printf(%fn,f(f(-1.0)+f(5.0);第12题给定程序FILL3.C的程序首先建立一个链表,函数fdelete()的功能是:

21、删除链表中数据域值为x的结点,并将链表的首指针返回给主函数。请改正函数fmax中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include struct node int data; struct node * next;struct node * fdelete(struct node *head,int x) struct node * p,*q; p=head;q=p; while(p!=NULL) if(p-data =x ) if (p=head) head; p; q=p; else q; p=p-next;

22、 else q; p; return head;struct node * finsert(struct node *head,int x) struct node * p; p=(struct node * )malloc (sizeof(struct node); p-data=x; p-next=head; return p;print(struct node * head) struct node * p; p=head; while(p) printf(%d,p-data); p=p-next; printf(n);main() struct node *h =NULL; int a

23、,i; for(i=0;i10;i+) a=rand()%1000; h=finsert(h,a); print(h); printf(Please input the delete node:n); scanf(%d,&a); h=fdelete(h,a); printf(after delete the node is:n); print(h); NONO();NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件*/ FILE *rf,*wf; int i,a; struct node *h =NULL,*p; rf=fopen(gc05.in,r); if (rf

24、= NULL) printf(数据文件gc05.in不存在!); return; for (i=0;idata); p=p-next; fprintf(wf,n); fscanf(rf,%d,&a); h=fdelete(h,a); fscanf(rf,%d,&a); h=fdelete(h,a); fscanf(rf,%d,&a); h=fdelete(h,a); fclose(rf); wf=fopen(gc05.out,w); p=h; while(p) fprintf(wf,%d,p-data); p=p-next; fprintf(wf,n); fclose(wf);第13题给定程序

25、MODI6.C中函数fun的功能是:读入一个整数m,计算如下公式的值. s = 1-例如: 若输入5,则应输出0.783333。请改正函数fun中的错误,使它能输出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include #include double fun(int m) double t=1.0; int i,j=1; for(i=2;i=m;i+) j; t=1.0/i; return t;main() int m; clrscr(); printf(nPlease enter 1 integer number:); scanf(%d,&m); printf(nThe result is %lfn,fun(m); NONO();NONO()/

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1