



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、。实验三选择结构程序设计一、实验目的1、 掌握建立和执行M文件的方法。2、 掌握利用if语句实现选择结构的方法。3、 掌握利用switch语句实现多分支选择结构的方法。4、 掌握 try语句的使用。二、实验内容1、 求分段函数的值。用if语句实现,分别输出x=-5.0,3.0,1.0,2.0,2.5,3.0,5.0时的 y值。 x=input('please input the value of x'); if x<0&x=-3y=x*x+x-6;elseif x>=0&x<5&x=2&x=3 y=x*x-5*x+6;else
2、y=x*x-x-1;endy please input the value of x-5.0y =14>> aaaaaplease input the value of x-3.0y =。1。11>> aaaaaplease input the value of x1.0y =2>> aaaaaplease input the value of x2.0y =1>> aaaaaplease input the value of x2.5y =-0.2500>> aaaaaplease input the value of x3.0y
3、=5。2。>> aaaaaplease input the value of x5.0y =192、 输入一个百分制成绩,要求输出成绩等级A、 B、C、 D、 E。其中90 分 100 分为 A, 80分89 分为 B, 70 分79 分为 C, 6069 分为 D,60 分以下为 E。要求:( 1) 分别用 if 语句和 switch 语句实现。( 2) 输入百分制成绩后要判断该成绩的合理性,对不合理性的成绩应输出出错信息。If语句 s=input('please input the score:'); if s>=90&s<=100rank=
4、'A'elseif s>=80&s<=89rank='B'elseif s>=70&s<=79rank='C'elseif s>=60&s<=69rank='D'elseif s>0&s<=59rank='E'elserank='wrong socre'endrank >>>> bbbplease input the score:94。3。rank =A>> bbbplease inp
5、ut the score:75rank =C>> bbbplease input the score:-3rank =wrong socre>> bbbplease input the score:456rank =wrong socre>>Switch 语句 score=input('please input the score:'); switch floor(score/10)case9,10。4。rank='A'case8rank='B'case7rank='C'case6rank=
6、39;D'case num2cell(0:5)rank='E'otherwiserank='wrong score'endrank=rank>> cccplease input the score:-3rank =wrong score>> cccplease input the score:456rank =wrong score>> cccplease input the score:94。5。rank =A>> cccplease input the score:45rank =E3、 硅谷公司员工的
7、工资计算方法如下:( 1)、工作时数超过 120 小时者,超过部分加发 15%。( 2)、工作时数低于 60 小时者,扣发 700 元。( 3)、其余按每小时 84 元计发。试编程按输入的工号和该号员工的工时数,计算应发工资。 number=input('please input work number:'); h=input('please input work hours:');if h>120 wage=120*84+(h-120)*84*1.15;elseif h<60wage=h*84-700;elsewage=h*84;endwage &
8、gt;> dddplease input work number:01。6。please input work hours:74wage =6216>> dddplease input work number:02please input work hours:53wage =3752>> dddplease input work number:03please input work hours:135wage =11529>>4、 设计程序,完成两位数的加、减、乘、除四则运算,即产生两个两位随机整数,再输入一个运算符号,做相应的运算,并显示相应的结果
9、。 x=input('please input a sign:','s'); x1=round(rand(1)*90+10); x2=round(rand(1)*90+10);if x='+' answer=x1+x2;。7。elseif x='-'answer=x1-x2;elseif x='*'answer=x1*x2;elseif x='/'answer=x1/x2;endx1x2answer > eeeplease input a sign:+x1 =83x2 =11answer =9
10、4>> eeeplease input a sign:-。8。x1 =23x2 =28answer =-5>>5、 建立 5× 6 矩阵,要求输出矩阵第n 行元素。当n 值超过矩阵的行数时,自动转为输出矩阵的最后一行元素,并给出出错信息。 x=rand(5,6); n=input('please input n:'); if n>0&n<=5y=x( n,:);elseif n>5;y=x(5,:);disp('wrong n');elseif n<0;y=( 'wrong n');endy。9。>> eeeplease input n:4y =0.93830.27890.47870.92220.92380.5945>> eeeplease
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国泵车行业发展分析及投资前景预测研究报告
- 2025-2030中国水管行业市场发展分析及商业模式与投融资战略研究报告
- 2025-2030中国有纺布行业发展分析及投资风险预测研究报告
- 2025-2030中国无溶剂层压机行业市场发展趋势与前景展望战略研究报告
- 河北理科数学试卷
- 治疗响应预测分析-洞察及研究
- 广东省初三上册数学试卷
- 2024年苏州市昆山市事业单位招聘考试真题
- 酒厂购买合同协议书范本
- 酒店房间优惠转让协议书
- GB/T 10045-2018非合金钢及细晶粒钢药芯焊丝
- GB 7099-2015食品安全国家标准糕点、面包
- 2023年纳雍县财政局系统事业单位招聘笔试题库及答案解析
- 2023年广东省普通高中学业水平考试及参考答案
- 建筑工程模板施工工艺技术要点讲义丰富课件
- 永能选煤厂生产安全事故应急救援预案
- 浙江省建设领域简易劳动合同(A4版本)
- 位置度公差以及其计算
- 氯化铵危险化学品安全周知卡
- 浙江省本级公务车辆租赁服务验收单(格式)
- 糖代谢紊乱的实验诊断
评论
0/150
提交评论