



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年应急救生系统项目合作计划书
- 2025年水基聚合物防水涂料项目合作计划书
- 智能交通系统建设工程施工合同
- 盐城市房屋租赁合同
- 小学生品德教育读后感
- 2025年饮料及冷饮服务项目发展计划
- 妊娠纹的专业知识
- Isonicotinamide-Standard-生命科学试剂-MCE
- Direct-blue-6-生命科学试剂-MCE
- 2025年鞋用乳液胶粘剂项目建议书
- 科技文献检索与利用PPT通用课件
- 《红楼梦讲稿》PPT课件
- DB33∕T 628.1-2021 交通建设工程工程量清单计价规范 第1部分:公路工程
- 吉祥喜金刚现证中品事业六支妙严(节录)
- 国民中小学九年一贯课程纲要语文学习领域(国语文)
- 最全的人教初中数学常用概念、公式和定理
- 桥面结构现浇部分施工方案
- 人教部编版四年级语文下册《第1课 古诗词三首》教学课件PPT小学优秀公开课
- 纸箱理论抗压强度、边压强度、耐破强度的计算
- 周收支统计报表excel模板
- 海管配重基础资料ppt课件
评论
0/150
提交评论