程序改错题答案

上传人:豆浆 文档编号:5903212 上传时间:2017-09-08 格式:DOCX 页数:8 大小:95.02KB
返回 下载 相关 举报
程序改错题答案_第1页
第1页 / 共8页
程序改错题答案_第2页
第2页 / 共8页
程序改错题答案_第3页
第3页 / 共8页
程序改错题答案_第4页
第4页 / 共8页
程序改错题答案_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《程序改错题答案》由会员分享,可在线阅读,更多相关《程序改错题答案(8页珍藏版)》请在金锄头文库上搜索。

1、C 程序改错题一、要求说明:1. 在考生文件夹的 Paper/CM 子文件夹中,已有 CM.c 文件2. 该程序中标有“/* 1 */”、“/* 2*/”、“/* 3*/”、“/* 4 */”等部分为需要程序改错的标志,其下一行程序语句有错误。考生需根据程序的功能自行改错,并调试运行程序;3. 单击“回答”按钮后进行程序改错;二、注意事项:1. 在改错时,不得删除改错标志(如:“/* 1 */”等),考生在该改错标志下方的下一行,根据程序功能改错;调试运行程序。2. 不得加行、减行、加句、减句。三、程序功能:1 输入x和正数 eps,计算多项式的和,直到末项的绝对值小于 eps 为止。 (1.

2、19)#include #include void main() double x,eps,s=1,t=1;/* 1 */float i=0;/* 2 */scanf(%lf%lf,&x,&eps);do i+;/* 3 */t=-t*x/i;s+=t;/* 4 */ while(fabs(t)=eps);printf(%fn,s);2 程序运行时,若输入 a,n 分别为 3,6,则输出下列表达式的值: (1.11)3+33+333+3333+33333+333333#include void main() int a,n,i; long s=0,t;/* 1 */scanf(%d%d,&a,

3、&n);/* 2 */t=0;/* 3 */for(i=1;ivoid main() int n,i;/* 1 */scanf(%d,&n);printf(%d=,n);/* 2 */i=2;/* 3 */while(n1)if(n%i=0) printf(%d*,i);/* 4 */n=n/i;else i+;printf(b n);4 程序运行时输入整数 n,则输出 n 的各位数字之和。 (1.12)例如:输入 n=1308,则输出 12;n=-3204,则输出 9#include void main() /* 1 */int n,s=0;scanf(%d,&n);/* 2 */n=n0)

4、/* 4 */s=s+n%10;n=n/10;printf(%dn,s);5 程序运行时,输入 10 个数,分别输出其中的最大值和最小值。(2.6)#include void main() float x,max,min; int i; /* 1 */for(i=1;imax) max=x;if(x#include #include void main() int i,n;struct axy float x,y;/* 1 */struct axy *a;/* 2 */scanf(%d,&n);a=(struct axy*) malloc(n*sizeof(struct axy);for(i=

5、0;iy);7 循环输入 x,n,调用递归函数计算,显示 x 的 n 次方。当输入 n 小于 0 时,结束循环。#include float f(float x,int n) /* 1 */if(n=0) return 1;else/* 2 */return x*f(x,n-1);void main() float y,z; int m;while(1) scanf(%f%d,&y,&m);/* 3 */if(mvoid main() char s180,s240; int j;/* 1 */int i=0;printf(Input the first string:);gets(s1);pr

6、intf(Input the second string:);gets(s2);/* 2*/while(s1i!= 0)i+;for(j=0;s2j!=0;j+) /* 3 */s1i+j=s2j;/* 4 */s1i+j= 0;puts(s1);9 用“选择法”对 10 个整数按升序排序。(2.12)#include #define N 10void main() int i,j,min,temp;int aN=5,4,3,2,1,9,8,7,6,0;printf(排序前:);/* 1 */for(i=0;i/* 1 */void DtoH(int n) int k=n & 0xf;if(n

7、4!=0) DtoH(n4);/* 2 */if(k,ai);/* 4 */DtoH(ai);putchar(n);11 输入一个字符串,将其中所有的非英文字母的字符删除后输出。(1.4)#include #include #includevoid main() char str81; int i,flag;/* 1 */gets(str);for(i=0;stri!=0;) flag=tolower(stri)=a & tolower(stri)void main() /* 1 */int i,j;int a6=1,3,5,7,9,11;int b7=2,5,7,9,12,16,3;/* 2

8、 */for(i=0;ivoid main() /* 1 */char a7= a2 汉字;int i,j,k;/* 2 */for(i=0;ai!= 0;i+) printf(a%d的机内码为:,i);for(j=1;jvoid main() char a=a2 汉字;int mm,i;/* 1 */printf(请输入密码:);/* 2 */scanf(%d,&mm);for(i=0;ai!=0;i+) /*各字符与 mm 作一次按位异或*/ai=aimm;puts(a);/* 各字符与 mm 再作一次按位异或 */* 3 */ for(i=0;ai!=0;i+)/* 4 */ai=aimm;puts(a);15 输入 n(小于 10 的正整数) ,输出如下形式的数组。例如:输入 n=5,数组为:输入 n=6,数组为:#include void main() int a99=0,i,j,n;/* 1 */while(scanf(%d,&n),n9); for(i=0;in;i+) /* 2 */for(j=0;j=i;j+)/* 3 */aij=i-j+1;for(i=0;in;i+) for(j=0;jn;j+) /* 4 */printf(%3d,aij);putchar(n);

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

当前位置:首页 > 行业资料 > 其它行业文档

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