已阅读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年秋部编人教版五年级上册道德与法治全册教学设计(新改版教材)
- 湖南省邵阳市2027届高三上学期第一次考试历史试题(含答案)
- 广东省深圳市2026年中考物理三模试卷附答案
- 2025-2026年物流师考试物流配送中心设计模拟试题
- 2026年烟花爆竹初期火情扑救考试题及答案
- 2025-2026年免疫系统基础知识测试卷
- 2026年烟草生产操作工测题库及答案
- 2026年学校卫生工作培训试卷(含答案)
- 2026年手术室专科护士考试试题及答案
- 中医医院2026年第三季度N1护理理论考试试题及答案
- 2026年严重精神障碍患者健康管理试题及答案
- 广东省工程勘察设计服务成本取费导则(2024版)
- 法检系统书记员招聘考试(公共基础知识)模拟试题及答案西藏2026
- 内审(气瓶检验机构)(2024版)-符合TSG Z7001-2021
- 手签章管理办法
- 回归突破:“生命实践”教育学论纲
- 江口县官和乡100万羽蛋鸡养殖基地项目环评报告
- 2023年05月重庆市药品技术审评查验中心招考35名工作人员(劳务派遣)笔试题库含答案解析
- 电子警察相机调试培训
评论
0/150
提交评论