C语言程序改错题及答案.doc_第1页
C语言程序改错题及答案.doc_第2页
C语言程序改错题及答案.doc_第3页
C语言程序改错题及答案.doc_第4页
C语言程序改错题及答案.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序调试1、#include #include void fun(char *s,char *t) int i,sl; sl=strlen(s); for(i=0;isl;i+) ti=si; for(i=0;isl;i+) /*1*/ / tsl+i=ss1-1-i; tsl+i=ssl-i; /*2*/ tsl=0; / tsl+s1=0;void main() char s100,t100; scanf(%s,s); fun(s,t); printf(%s,t);2、#include void main() int n,i; scanf(%d,&n); /* 1 */ i=1; / i=2; while(n1) if(n%i=0) printf(%dt,i); n/=i; else /* 2 */ n+; / i+;3、#include #include void main() int n,s=0; scanf(%d,&n); n=fabs(n); /* 1 */ while(n1) / 1n 2n!=0 s=s+n%10; /* 2 */ n=n%10; / n=n/10; printf(%dn,s);4、#includevoid itoa(long i,char *s) if(i=0) return; /* 1 */ *s = 1+i%10; /*s = 0+i%10; itoa(i/10,s-1);void main() long n; char str7=; scanf(%ld,&n); /* 2 */ itoa(n,str+6); / itoa(n,str+5); printf(%s,str);5、#include #define N 10void main() int i,j,min,temp; int aN=5,4,3,2,1,9,8,7,6,0; printf(nThe array is:n); /* 输出数组元素 */ for (i=0;iN;i+) printf(%5d,ai); for (i=0;iN-1;i+) /* 排序操作 */ min = i; for (j=i+1; jN; j+) /* 1 */ if (amin=aj) /* 2 */ temp=amin; amin=aj; aj=temp; /* 数据交换 */ temp=amin; amin=ai; ai=temp; printf(nThe sorted numbers: n); /* 输出排序结果 */ for (i=0;iN;i+) printf(%5d,ai); printf(n);6、#include void main() char s180,s240; int i=0,j=0; printf(nInput the first string:); scanf(%s,s1); printf(nInput the second string:); scanf(%s,s2); while (s1i !=0) /* 1 */ i+1; / i= i+1; while (s2j !=0) /* 2 */ s1+i=s2+j; /* 拼接字符到s1 */ /s1i+=s2j+; s1i =0; printf(nNew string: %s,s1);7、#include void main() int i,a,n,t=0; /* 1 */ s=0; / int s=0; scanf(%d%d,&a,&n);for(i=1;i=n;i+) /* 2 */ t=t*10+i; / t=t*10+1; s=s+t; s=s*a; printf(%dn,s);8、#include #include void main() float x,eps,s=1,t=1,i=1; scanf(%f%f,&x,&eps); do /* 1 */ t=-t*x/+i; / t = -t * x / i+; s+=t; /* 2 */ while(fabs(t)=eps) ; printf(%fn,s);9、#include void main() float x,max,min; int i; /* 1 */ for(i=0;i=10;i+) / i10 循环的个数不对,如果imax) max=x; if(xmin) min=x; printf(%f,%fn,max,min);10、. 在考生目录下,有Modify.c程序,该程序中/* N */的下一行中有错误,请改正(注意:不得加行、减行、加句、减句,否则后果自负)。该程序功能:分别统计字符串中所有英文字母中的各元音字母个数。#include #include void main() char a80; int n5=0,i; gets(a); for(i=0; ai!=0; i+) /* 1 */ switch(tolower(a+i) / (tolower(ai) case a: n0+; break; case e: n1+; break; case i: n2+; break; case o: n3+; break; /* 2 */ case U: n4+; break; / u for(i=0;i5;i+) printf(%dn,ni); 11、在考生目录下,有Modify.c程序,该程序中/* N */的下一行中有错误,请改正(注意:不得加行、减行、加句、减句,否则后果自负)该程序功能:输入n(0n10)后,输出1个数字金字塔。如输入n为4,则输出: 1 222 33333 4444444 #include void main() int i,j,n; /* 1 */ scanf(%d, n); / &n for(i=1;i=n;i+) for(j=1;j=n+1-i;j+) putchar( ); for(j=1;j=2*i-1;j+) putchar(char)(i+48); /* 2 */ putchar(n); / n 12、 在考生目录下,有Modify.c程序,该程序中“/* N */”的下一行中有错误,请改正(注意:不得加行、减/行、加句、减句,否则后果自负)。 该程序功能:输入n以及小于n个字符的字符串,将字符串中所有小写字母改为相应的大写字母后,输出该字符串。 #include #include #include void main() i

温馨提示

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

评论

0/150

提交评论