版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1在考生目录下,给定程序MODI1.C的功能是:先将在字符串s中的字符按正序存放到t串中,然后把s中的字符按逆序连接到t串的后面。 例如:当s中的字符串为:ABCDE时, 则t中的字符串应为:ABCDEEDCBA。 main() char s80,t80; int i, sl; clrscr(); printf(nPlease enter string s:); scanf(%s, s); sl = strlen(s); /*found*/ /*for( i=0; i=sl; i+=2)*/ for( i=0; isl; i+) ti = si; for (i=0; isl; i+) tsl+
2、i = ssl-i-1; /*found*/ /* tsl = 0;*/ tsl+i = 0; printf(The result is: %sn, t); 2 从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。 例如,当s中的数为:时,t中的数为:7531。 程序中有两处错误,错误都在提示行:/*found*/的下面一行,请考生注意。#include #include main() long s, t, sl=10; clrscr(); printf(nPlease enter s:); scanf(%ld, &s); /*found*/ /* t = s / 10;*/
3、t = s % 10;while ( s 0) s = s/100; t = s%10 * sl + t; /*found*/ /*sl = sl*100;*/ sl = sl*10; printf(The result is: %ldn, t); 3. 将n个无序整数从小到大排序。#include #include #include main() int a20=9,3,0,4,1,2,5,6,8,10,7, n=11; int i, j, p, t; clrscr(); printf( nnBefore sorting %d numbers:n, n ); j = 0; for ( i =
4、 1; i = n; i+, j+ ) printf( %4d, aj ); if ( !( i%10 ) ) printf( n ); printf(n); for ( j = 0; jn-1 ; j+ ) p = j; /*found*/*for ( i=j+1; in-1 ; i+ )*/for ( i=j+1; iai ) /*found*/*t=i;*/p=i; if ( p!=j ) t = aj; aj = ap; ap = t; printf( nAfter sorting %d numbers:n, n ); j = 0; for ( i = 1; i = n; i+, j+
5、 ) printf( %4d, aj ); if ( !( i%10 ) ) printf( n ); printf(n); 4. 在考生目录下,给定程序MODI1.C的功能是: 求两实数平方根之和,输出此和。 例如:输入12和20,输出结果是:y = 7.。#include #include main( ) /*found*/*int a, b, y;*/double a, b, y; clrscr(); printf ( Enter a & b : ); scanf (%lf%lf, &a, &b ); /*found*/*y = sqr(a)+sqr(b) ;*/y = sqrt(a)+
6、sqrt(b) ; printf (y = %f n, y ); 5. 打印一个如下的九九乘法表的一部分: 1 * 1 = 1 2 * 1 = 2 2 * 2 = 4 3 * 1 = 3 3 * 2 = 6 3 * 3 = 9 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16#include #include #include #include main() int i,j,k; clrscr(); for(i=1;i=4;i+) /*found*/ /*for(j=1;j=4;j+)*/ for(j=1;j=i;j+) printf(%3d *%3d =%3
7、d,i,j,i*j); /*found*/ /*printf(n);*/printf(n); 6.学习优良奖的条件如下:所考5门课的总成绩在450分(含)以上;或者每门课都在88分(含)以上。输入某学生5门课的考试成绩,输出是否够学习优良奖的条件。#include #include #include #include main() int score,sum=0; int i,n=0; clrscr(); for(i=1;i=88) n+; /*found*/*if(sum=450 & n=5 )*/if(sum=450|n=5 ) printf(The student is very goo
8、d!n); else printf(The student is not very good!n); 7.输出100200之间既不能被3整除也不能被7整除的整数并统计这些整数的个数,要求每行输出8个数。 #include #include #include #include main() int i; /*found*/*int n;*/int n=0; clrscr(); for(i=100;i=200;i+) /*found*/ /*if(i%3=0&i%7=0)*/ if(i%3!=0&i%7!=0) if(n%8=0) printf(n); printf(%6d,i); n+; pri
9、ntf(nNumbers are: %dn,n); 8.打印输出以下图形 * * * * * #include #include #include #include main() int i,j; clrscr(); for(i=1;i=5;i+) /*found*/ /*printf n);*/printf(n); for(j=1;j=10-i;j+) printf( ); /*found*/ /* for(j=1;j=2*i+1;j+)*/ for(j=1;j=2*i-1;j+) printf(*); printf(n); 9. 20求 n!(即求:1!+2!+3!+ + 20!) n=1
10、#include #include #include #include main() /*found*/ /*long int s,t;* 注意:用%e打印*/ float s,t; int n; s=0;t=1; clrscr(); /*found*/ /* for(n=1;n20;n+) */ for(n=0;n20;n+) t=t*(n+1); s=s+t; printf(1!+2!+3!+ +20!=%en,s); 10.输入一个百分制成绩,打印出五级记分成绩。考试成绩在90分或90分以上为优秀,8089分为良好,7079为中等,6069为及格,低于60分为不及格。#include #
11、include #include #include main() int score,t; clrscr(); printf(Please enter a score:); do scanf(%d,&score); while(score100); t=score/10; /*found*/*switch(score)*/switch(t) case 10: case 9:printf(Excellent!n);break; case 8:printf(Good!n);break; case 7:printf(Middle!n);break; case 6:printf(Pass!n);bre
12、ak; /*found*/ /*else :printf(Fail!n);*/ default: printf(Fail!n); 11. 求一维数组a中的最大元素及其下标。例如,当一维数组a中的元素为:34,4,2,7,3,12,5,8,5,9,程序的输出应为:The max is: 34,pos is: 0 。#include #include int max; maxarr(int arr ) int pos,i; /*found*/ /*max = 0;*/max=arr0; pos = 0; for ( i=1; i arri)*/ if (max arri) max = arri;p
13、os = i; return (pos); main() int a10=34,4,2,7,3,12,5,8,5,9; clrscr(); printf(The max is: %d ,pos is: %dn, max , maxarr(a); 12.求二维数组a中的最小值。 例如,当二维数组a中的元素为: 4 4 34 7 3 12 5 6 5程序的输出应为:The min is: 3 。#include #include int arrmin( int arr33) int i,j,min; /*found*/*min=0;*/min=arr00; for ( i=0; i3; i+) f
14、or ( j=0; j arrij) min = arrij; return (min); main() int a33=4,4,34,7,3,12,5,6,5,i,j,n; clrscr(); /*found*/ /*n = arrmin( a00);*/n = arrmin(a); printf(The min is: %dn,n); 13.求一维数组a中值为奇数的元素之和。例如,当一维数组a中的元素为:11,4,2,7,3,12,5,34,5,9程序的输出应为:The result is: 40。#include #include main() int arr10=11,4,2,7,3,
15、12,5,34,5,9,i; /*found*/*int s=0;*/int s=arr0; clrscr(); for ( i=1; i10; i+) /*found*/ /*if (i % 2 = 1)*/ if (arri % 2 = 1) s = s + arri; printf(The result is: %dn, s); 14.求一维数组a中值为奇数的元素的平均值。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9,21,18 ,程序的输出应为:The result is: 8.33。#include #include double average( in
16、t arr , int n ) int k=0,i; double s; s = 0; for ( i=0 ;in; i+) /*found*/ /*if (arri % 2 = 1)*/ if (arri % 2 =1) s = s + arri; k+; return (s/k) ; main() int a12=10,4,2,7,3,12,5,34,5,9,21,18; double s; clrscr(); /*found*/ /*s = average(a12,12);*/s = average(a,12); printf(The result is: %.2fn, s); 15.求一维数组a中所有元素的平均值。例如,当一维数组a中的元素为:10,4,2,7,3,12,5,34,5,9 ,程序的输出应为:The aver is: 9. 。#include
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年泰山护理职业学院单招职业技能考试题库有答案详细解析
- 2026年青海交通职业技术学院单招职业适应性测试题库有答案详细解析
- 2026年广东舞蹈戏剧职业学院单招职业技能考试题库附答案详细解析
- 2026内蒙古赤峰市红山区蒙艺中等职业技术学校招聘37人考试参考试题及答案解析
- 运城市盐湖区2025年网格员笔试真题及答案解析
- 电商天猫客服中心制度手册
- 2026年黑龙江省七台河市高职单招综合素质考试题库及答案详细解析
- 2026年黑龙江农业职业技术学院单招职业适应性测试题库有答案详细解析
- 2026年齐齐哈尔高等师范专科学校单招综合素质考试题库及答案详细解析
- 迈瑞心电监护仪的操作技巧
- 副食品配送卫生管理制度
- 新疆神火煤电有限公司电解铝大修渣无害化处理综合利用项目环评报告
- GB/T 45554-2025种猪生产性能测定技术规范
- 单兵战术动作低姿匍匐前进教案
- 2025新人教版七年级下册英语 Unit 8知识点梳理及语法讲义(答案版)
- 水库安全管理培训
- 工程劳务外包合同范本大全
- 统编版语文四年级下册 第一单元基础过关卷(试题)
- 自考《13180操作系统》考前强化练习试题库及答案
- 人工智能芯片设计 课件 周巍 第4-7章-人工智能与深度学习 -人工智能芯片架构设计
- 医院患者安全与防范措施管理规章制度
评论
0/150
提交评论