




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 水生植物生态毒理学创新创业项目商业计划书
- 智能养老服务系统创新创业项目商业计划书
- 坚果果仁果冻果脯创新创业项目商业计划书
- 工业品电商创新创业项目商业计划书
- 智能制造车间自动化系统设计
- 高职电子技术基础实验教学指导书
- 装载机操作安全规范与职责
- 新股东权益分配方案解析
- 建筑施工安全隐患排查典型案例
- 2025年检验检测机构内审员考试试卷(附答案)
- 西畴殡葬管理办法
- 新生儿支气管肺炎护理查房
- 小学生意外伤害课件
- 银行外包人员管理办法
- 学堂在线 逻辑学概论 章节测试答案
- 2024年法考主观题刑法真题(回忆版)解析与复习重点
- 招生表彰活动方案
- 2025年安徽高考地理试卷真题(含答案解析)
- 学校党组织家访活动方案
- 数字媒体技术专业教学标准(高等职业教育专科)2025修订
- 妊娠合并心脏病疾病查房
评论
0/150
提交评论