已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C程序设计教程书后第一章习题详解1.求出10个数中的最大数:/*用一个数组来存放10个数*/#includemain()int a10,i,max;printf(Please enter 10 numbers:n);for(i=0;i10;i+) scanf(%d,a+i);/*&ai=a+i*/max=a0;for(i=1;imax) max=ai;printf(The max number is %d,max);getch();/*用一个变量来存放10个数*/#includemain()int i,m,max;printf(Please enter 10 numbers:n);scanf(%d,&m);max=m;for(i=2;imax) max=m; printf(The max number is %d,max);getch();2.求两个正整数的最大公约数:/*逐个尝试法求两个正整数的最大公约数*/#includemain()int m,n,i,t;printf(Please enter two positive integral numbers:n);scanf(%d %d,&m,&n);for(i=1;i=m&i=n;i+) if(m%i=0&n%i=0) t=i;printf(The highest common divissor of the two numbers is %d,t);getch();/*辗转相除法求两个正整数的最大公约数*/#includemain()int m,n,r;printf(Please enter two positive integral numbers:n);scanf(%d %d,&m,&n);r=m%n;while(r!=0)m=n; n=r; r=m%n;printf(The highest common divissor of the two numbers is %d,n);getch();/*辗转相减法求两个正整数的最大公约数*/#includemain()int m,n,r,t;printf(Please enter two positive integral numbers:n);scanf(%d %d,&m,&n);if(mn) t=m; m=n; n=t; r=m-n;while(r!=0)m=n; n=r; if(mn) t=m; m=n; n=t; r=m-n;printf(The highest common divissor of the two numbers is %d,n);getch();3.韩信点兵:#includemain()int m,n,i;printf(Please enter the poseble range (m to n):n);scanf(%d %d,&m,&n);printf(The posible number is:n);for(i=m;i=n;i+) if(i%3=1&i%5=2&i%7=4&i%13=6) printf(%dn,i);getch();C程序设计教程书后第二章习题详解3.从键盘上输入两个变量的值,交换这两个变量的值后输出:/*交换时引进变量t*/#includemain()int a,b,t;printf(Please enter two numbers:n);scanf(%d %d,&a,&b);t=a;a=b;b=t;printf(The changed two numbers are:n%d %d,a,b);getch();/*交换时不引进变量*/#includemain()int a,b;printf(Please enter two numbers:n);scanf(%d %d,&a,&b);a=b-a;b=b-a;a=a+b;printf(The changed two numbers are:n%d %d,a,b);getch();/*交换时用位运算*/#includemain()int a,b;printf(Please enter two numbers:n);scanf(%d %d,&a,&b);a=ab;b=ba;a=ab;printf(The changed two numbers are:n%d %d,a,b);getch();4.将从键盘上输入的任一字符分别以字符和十进制数两种方式输出:#includemain()char c;printf(Pleas
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人教版七年级语文2026期末模拟卷
- 布谷鸟图谱课件
- 2026年中远海运模拟试卷带答案
- 2026年肛肠科模拟试题(含答案)
- 2026年人保寿险考试模拟试卷及答案
- 2026年护理n2模拟试卷(含答案)
- 2026年鲁美校模拟试卷带答案
- 综管类考研模拟试卷及答案
- 2026年信息安全工程师专业技术资格认证考试模拟试卷及参考答案
- 2026年思政考试模拟试卷题型及答案
- 片碱溶解及片碱、液碱仓储经营项目环境影响报告表
- 2026年机械设计与人工智能的融合实践
- 选矿学谢广元课件
- 猪场饲养员合同协议
- 2025智能体发展与治理研究报告
- 膜性肾病的中医护理方案
- 房屋市政工程生产安全重大事故隐患判定标准培训课件
- 洗鞋店活动促销活动方案
- 二氧化碳地质封存与检测 课件全套 第1-7章-绪论、CO2多相流基础理化性质-矿场应用
- T/CASTEM 1007-2022技术经理人能力评价规范
- 人工破膜指征及操作规范
评论
0/150
提交评论