



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序改错题(共15题)1、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中所有元素的平均值,结果保留两位小数。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9程序的输出应为:The aver is: 9.10 。#include <conio.h>#include <stdio.h> void main() int a10=10,4,2,7,3,12,5,34,5,9,i;float aver,s; /*found*/ int aver,s; /*found*/s=a0; s = 0; for ( i=1; i<10; i+)
2、 s += ai; aver = s / i; printf("The aver is: %.2fn", aver);2、在考生文件夹下,给定程序MODI.C的功能是:求二维数组a中的最大值和最小值。 例如,当二维数组a中的元素为: 4 4 34 37 3 12 5 6 5程序的输出应为:The max is: 37 The min is: 3 。 #include <conio.h> #include <stdio.h> void main() int a33=4,4,34,37,3,12,5,6,5,i,j,max,min; max = min
3、= a00; for ( i=0; i<3; i+)for(j=0;j<3;j+) /*found*/ for ( j=1; j<3; j+) if ( max < aij ) max = aij; /*found*/if(min>aij) if (min < aij) min = aij; printf("The max is: %dn", max); printf("The min is: %dn", min); 3、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中的最大元素及其下标。例如,当一维数组a
4、中的元素为:1,4,2,7,3,12,5,34,5,9,程序的输出应为:The max is: 34,pos is: 7 。 #include <conio.h> #include <stdio.h> void main() int a10=1,4,2,7,3,12,5,34,5,9,i,max,pos; max = a0; pos = 0; for ( i=1; i<10; i+) /*found*/if(max<ai) if (max > ai) max = ai; /*found*/pos=i;i = pos; printf("The
5、max is: %d ,pos is: %dn", max , pos);4、在考生文件夹下,给定程序MODI.C的功能是:求二维数组a中的最小值。 例如,当二维数组a中的元素为: 4 2 34 7 3 12 5 6 5程序的输出应为:The min is: 2 。#include <conio.h> #include <stdio.h> void main() int a33=4,2,34,7,3,12,5,6,5,i,j,min; min = a00;for(i=0;i<3;i+) /*found*/ for ( i=1; i<3; i+) f
6、or ( j=0; j<3; j+) if (min > aij) /*found*/min=aij;min = aij; printf("The min is: %dn", min); 5、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中所有元素的平均值。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9程序的输出应为:The aver is: 9.10 。#include <conio.h>#include <stdio.h> void main() int a10=10,4,2,7,3,12,5,
7、34,5,9,i; double aver,s; s = a0;for ( i=1; i<10; i+) /*found*/ for ( i=0; i<10; i+) /*found*/s = s + ai; s = s + i; aver = s / i; printf("The aver is: %.2fn", aver);6、在考生文件夹下,给定程序MODI.C的功能是:输入一个百分制成绩,打印出五级记分成绩。考试成绩在90分或90分以上为优秀,8089分为良好,7079为中等,6069为及格,低于60分为不及格。 #include <stdio.h
8、> #include <conio.h> #include <stdlib.h> #include <math.h> void main() int score,t; printf("Please enter a score:"); do scanf("%d",&score); while(score<0|score>100); t=score/10;switch(t) /*found*/ switch(score) case 10: case 9:printf("优秀!n"
9、;);break; case 8:printf("良好!n");break; case 7:printf("中等!n");break; case 6:printf("及格!n");break; /*found*/ else :printf("不及格!n");default: printf("不及格!n"); 7、在考生文件夹下,给定程序MODI.C的功能是:输出100200之间既不能被3整除也不能被7整除的整数并统计这些整数的个数,要求每行输出8个数。#include <stdio.h&g
10、t; #include <conio.h> #include <stdlib.h> #include <math.h> void main() int i; /*found*/int n=0; int n; for(i=100;i<=200;i+) /*found*/ if(i%3=0&&i%7=0) if(n%8=0) printf("n");if(i%3!=0 && i%7!=0) printf("%6d",i); n+; printf("nNumbers are:
11、%dn",n);8、在考生文件夹下,给定程序MODI.C的功能是:学习优良奖的条件如下:所考5门课的总成绩在450分(含)以上;或者每门课都在88分(含)以上。输入某学生5门课的考试成绩,输出是否够学习优良奖的条件。 #include <stdio.h> main() int score,sum=0; int i,n=0; for(i=1;i<=5;i+) scanf("%d",&score); sum+=score;if(score>=88) n+; /*found*/ if(score<=88) n+; if(sum>
12、;=450 | n=5 ) /*found*/ if(sum>=450 && n=5 ) printf("The student is very good!n"); else printf("The student is not very good!n"); 9、在考生文件夹下,给定程序MODI.C的功能是:输出200300之间的所有素数,要求每行输出8个素数。#include <stdio.h> #include <math.h> main() int m,j,n=0,k; for(m=200;m<=
13、300;m+) k=sqrt(m); for(j=2;j<=k;j+) /*found*/if(m%j=0) break; if(m%j=0) continue; if(j>k) if(n%8=0) printf("n"); /*found*/printf("%d,",m); printf("%d,",j); n+; 10、在考生文件夹下,给定程序MODI.C的功能是:求出a所指数组中最小数(规定最小数不在a0中),最小数和a0中的数对调。例如数组中原有的数为:7、10、12、0、3、6、9、11、5、8,输出的结果为:0
14、、10、12、7、3、6、9、11、5、8。 #include <conio.h> #include <stdio.h> #define N 20 main( ) int aN=7,10,12,0,3,6,9,11,5,8, n=10, i, k,m,min,t; for ( i = 0; i<n; i+) printf("%d ",ai); printf("n"); min= a0; m=0; for ( k = 0; k < n; k+ ) /*found*/ if(ak<min) if ( ak>mi
15、n ) min = ak; m = k; /*found*/ t = a0; am=a0; am = t; for ( i=0; i<n; i+ ) printf("%d ",ai); printf("n");11、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中的最小元素及其下标。例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9,程序的输出应为:The min is: 1,pos is: 0 。#include <conio.h> #include <stdio.h> main() in
16、t a10=1,4,2,7,3,12,5,34,5,9,i,min,pos; /*found*/min=a0; min = 0; pos = 0; for ( i=1; i<10; i+) if (min > ai) min = ai; /*found*/pos=i;pos = ai; printf("The min is: %d ,pos is: %dn", min , pos);12、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中值为偶数的元素之和。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,程序的输出应为:T
17、he result is: 62。#include <conio.h> #include <stdio.h> sum ( int arr ,int n ) int i,s; s = 0; for ( i=0; i<n; i+) if (arri % 2 = 0) /*found*/s=s+arri; s = s + i; return (s); void main() int a10=10,4,2,7,3,12,5,34,5,9,s;s=sum(a,10); /*found*/ sum( a ,2 ); printf("The result is: %d
18、n", s); t=a0;a0=am;am=t;13、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中的最大元素及其下标。例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9,程序的输出应为:The max is: 34,pos is: 7 。#include <conio.h> #include <stdio.h> void main() int a10=1,4,2,7,3,12,5,34,5,9,i,max,pos; max = a0; pos = 0; for ( i=1; i<10; i+) /*found*/if
19、(max<ai) if (max > ai) /*found*/max=ai; max = a; pos =i; printf("The max is: %d ,pos is: %dn", max , pos); 14、在考生文件夹下,给定程序MODI.C的功能是:求一维数组a中值为奇数的元素之和。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9, 21 ,19程序的输出应为:The result is: 69。#include <conio.h> #include <stdio.h> int sum( int b ,int n ) int i,s = 0; fo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 分布式能源系统与能源大数据分析考核试卷
- 2024年监理工程师合同管理工程合同变更程序知识点练习
- 废水处理技术生态修复应用考核试卷
- 运动伤害预防与赛事医疗救援的融合策略考核试卷
- 兵器试验面试题及答案
- 法医内部考试题及答案
- 战略协同与目标一致性与否考核试卷
- 风机公司面试题及答案
- 绍兴市焊工考试试题及答案
- 生物演化试题及答案
- GB/T 9765-2009轮胎气门嘴螺纹
- GB/T 23806-2009精细陶瓷断裂韧性试验方法单边预裂纹梁(SEPB)法
- 2022年04月四川宜宾市叙州区面向区内外考试选调在编在职教师136人考试押题库【1000题】含答案附带详解析
- FZ/T 74001-2020纺织品针织运动护具
- 图解“双均线双交叉”期货、股票操作系统课件
- 宫外孕右输卵管妊娠腹腔镜下盆腔粘连分解术、右输卵管妊娠开窗取胚术手术记录模板
- 教科版 科学小学二年级下册期末测试卷及参考答案(基础题)
- 美军标电子装备环境试验-mil-std-810g
- 混凝土重力坝设计说明书
- 应用回归分析(第三版)何晓群_刘文卿_课后习题答案_完整版
- 道路及两侧便道保洁方案.docx
评论
0/150
提交评论