




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1 第五章八大题编程题答案 第五章八大题编程题答案 1 编写一个程序 输入编写一个程序 输入 a b c 三个值 输出其中最大值 三个值 输出其中最大值 方法一 方法一 main int a b c max printf 请输入三个数请输入三个数 a b c n scanf d d d max a if max b max b if maxb a b temp 为为 a b 中较大值中较大值 max temp c max c 在在 temp 和和 c 中比较出最大值中比较出最大值 printf max d n max 运行结果 运行结果 input three integer 12 34 9 max 34 2 编程实现 输入整数 编程实现 输入整数 a 和和 b 若 若 a2 b2 大于大于 100 则输出 则输出 a2 b2 百位以上的数百位以上的数 字 否则输出两数之和字 否则输出两数之和 main int a b scanf d d if a a b b 100 printf d a a b b 100 else printf d a b 3 有一函数 有一函数 y 10 113 101 12 1 xx xx xx 写一程序 输入 写一程序 输入 x 输出 输出 y 值 值 main 2 int x y printf input x scanf d x if x 1 当当 x 1 时 求对应时 求对应 y 值值 y x else if x100 score9999 place 5 else if num 999 place 4 else if num 99 place 3 else if num 9 place 2 else place 1 printf place d n place 输出位数输出位数 printf shuzi is ten thousand num 10000 以下五行分别求万位 千位 百位 十位 个位数字以下五行分别求万位 千位 百位 十位 个位数字 thousand int num ten thousand 10000 1000 hundred int num ten thousand 10000 thousand 1000 100 ten int num ten thousand 10000 thousand 1000 hundred 100 10 indiv int num ten thousand 10000 thousand 1000 hundred 100 ten 10 switch place 根据位数判断应该输出哪几位数字根据位数判断应该输出哪几位数字 case 5 printf d d d d d ten thousand thousand hundr ed ten indiv 正序输出正序输出 printf ninvert is printf d d d d d n indiv ten hundred thousand ten thousand 逆序输出逆序输出 break case 4 printf d d d d thousand hundred ten indiv printf ninvert is printf d d d d n indiv ten hundred thousand break case 3 printf d d d hundred ten indiv printf ninvert is printf d d d n indiv ten hundred break case 2 printf d d ten indiv printf ninvert is printf d d n indiv ten break case 1 printf d indiv printf ninvert is printf d n indiv break 运行结果 运行结果 input 0 99999 98765 4 place 5 shuzi is 9 8 7 6 5 invert is 56789 6 试编程判断输入的正整数是否既是 试编程判断输入的正整数是否既是 5 又是又是 7 的整数倍 若是 则输出的整数倍 若是 则输出 yes 否则输出 否则输出 no main int x printf input x scanf d x if x 5 0 x 7 0 printf yes else printf no 运行情况 运行情况 inupt x 35 yes 思考 思考 if 中的条件表达式可否改成中的条件表达式可否改成 x 5 x 7 7 编制程序要求输入正整数 编制程序要求输入正整数 a 和和 b 若 若 a2 b2大于大于 100 则输出 则输出 a2 b2百位以上的数字 百位以上的数字 否则输出两数之和 否则输出两数之和 main int a b x y printf input a b scanf d d a b x a a b b if x 100 若若 a2 b2 100 y x 100 y 为为 a2 b2 百位以上的数字百位以上的数字 printf d y else printf d a b 运行情况 运行情况 input a b 10 8 1 8 已知银行整存整取存款不同期限的月息利率分别为 已知银行整存整取存款不同期限的月息利率分别为 月息利率 月息利率 年期限 年期限 年期限 年期限 年期限 8 84 0 5 75 0 3 69 0 2 66 0 1 63 0 输入存款的本金和年限 求到期时能从银行得到的利息与本金的合计 输入存款的本金和年限 求到期时能从银行得到的利息与本金的合计 利息的计算公 利息的计算公 式为 利息 本金式为 利息 本金 月息利率月息利率 12 存款年限 存款年限 include stdio h 5 main int year float money rate total money 本金 本金 rate 月利率 月利率 total 本利合计 本利合计 printf Enter money and year scanf f d money year 输入本金和存款年限输入本金和存款年限 if year 1 rate 0 0063 根据年限确定利率根据年限确定利率 else if year 2 rate 0 0066 else if year 3 rate 0 0069 else if year 5 rate 0 0075 else if year 8 rate 0 0084 else rate 0 0 total money money rate 12 year 计算到期的本利合计计算到期的本利合计 printf Total 2f n total 9 输入年份和月份 求该月有多少天 输入年份和月份 求该月有多少天 main int year month days printf Enter year and month scanf d d year month switch month case 1 case 3 case 5 case 7 case 8 case 10 case 12 处理处理 大大 月月 days 31 break case 4 case 6 case 9 case 11 处理处理 小小 月月 days 30 break case 2 处理处理 平平 月月 if year 4 0 year 100 0 year 400 0 days 29 如果是闰年如果是闰年 else days 28 不是闰年不是闰年 break default printf Input error n 月份输入错误月份输入错误 days 0 if days 0 printf d d is d days n year month days 10 编制菜单程序 在屏幕上显示时间表 根据用户的选择 显示不同的问候信息 编制菜单程序 在屏幕上显示时间表 根据用户的选择 显示不同的问候信息 include stdio h main char ch printf TIME n 打印时间表菜单打印时间表菜单 printf 1 morning n printf 2 afternoon n printf 3 night n printf Your choice ch getchar 从键盘输入用户的选择从键盘输入用户的选择 6 switch ch 根据选择进行不同处理根据选择进行不同处理 case 1 printf n Good morning n break case 2 printf n Good afternoon n break case 3 printf n Good night n break default printf Selection wrong n 思考 如去除思考 如去除 break 语句 执行情况将如何 语句 执行情况将如何 11 编写简单的计算器程序 根据用户输入的两个操作数和运算符 显示计算结果 编写简单的计算器程序 根据用户输入的两个操作数和运算符 显示计算结果 设运算符包括 设运算符包括 include stdio h main float data1 data2 定义两个操作数变量定义两个操作数变量 char op 定义操作符定义操作符 printf Enter your expression scanf f c f data1 op data2 输入要计算的表达式输入要计算的表达式 switch op 根据操作符对根据操作符对 data1 data2 进行相应运算进行相应运算 case 处理加法处理加法 printf 2f 2f 2f n data1 data2 data1 data2 break case 处理减法处理减法 printf 2f 2f 2f n data1 data2 data1 data2 break case 处理乘法处理乘法 printf 2f 2f 2f n data1 data2 data1 data2 break case 处理除法处理除法 if data2 0 若除数为若除数为 0 printf Divisor is zero n else printf 2f 2f 2f n data1 data2 data1 data2 break default 输入其它运算符输入其它运算符 printf Unkwown operater n 12 通过键盘输入字符 判断其为控制 数字 大写字母 小写字母和其他字母的哪
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 福建龙岩第一中学2024~2025学年高一下册第一次月考数学试题
- 家庭临终关怀服务支持考核试卷
- 光缆通信在智能电网电力市场交易信息传输中的应用考核试卷
- 光刻工艺中的图案转移技术挑战考核试卷
- 印刷企业绿色采购成本效益分析考核试卷
- 农村物流配送效率影响因素及对策研究考核试卷
- 电感器在高频电路中的磁路损耗分析考核试卷
- 情商在激励团队中的作用考核试卷
- 企业多元化战略的执行与监控考核试卷
- 职业卫生法律法规遵守与违法责任分析考核试卷
- 2025云南中考历史真题及答案
- 四川省成都市蓉城联盟2024-2025学年高一下学期6月期末考试物理试题(含答案)
- 压轴训练:全等三角形(多解、动点、新定义型压轴)(原卷版)
- 2025年安庆望江县融媒体中心专业技术人员招聘考试笔试试题(含答案)
- 2025公文写作考试真题库(含答案)
- T/CCS 075-2023煤矿柔性薄喷材料喷涂施工技术要求
- 2025海南中考:政治必考知识点
- 吊装起重作业安全培训
- DLT 5035-2016 发电厂供暖通风与空气调节设计规范
- 中药学学习要点
- 合同到期不续签领失业金(2025年版)
评论
0/150
提交评论