matlab实验三选择结构程序设计,matlab选择结构程序的设计答案

《matlab选择结构程序的设计答案》由会员分享,可在线阅读,更多相关《matlab选择结构程序的设计答案(9页珍藏版)》请在人人文库网上搜索。

1、实验三 选择结构程序设计一、实验目的1、掌握建立和执行 M文件的方法。2、掌握利用 if 语句实现选择结构的方法。3、掌握利用 switch 语句实现多分支选择结构的方法。4、掌握 try 语句的使用。二、实验容时的 y1 、 求分段函数的值。用 if 语句实现,分别输出 x=-5.0,3.0,1.0,2.0,2.5,3.0,5.0 值。 x=input(please input the value of x);if x=0&x aaaaaplease input the value of x-3.011 aaaaaplease input the value of x1.0 y =2 aaa。

2、aaplease input the value of x2.0y =1 aaaaaplease input the value of x2.5 y =-0.2500 aaaaaplease input the value of x3.0y =5 aaaaa please input the value of x5.0192、输入一个百分制成绩,要求输出成绩等级A、B、C D E。其中90分100分为A, 80分89分为B, 70分79分为C, 6069分为D, 60分以下为 E。要求:( 1 ) 分别用 if 语句和 switch 语句实现。(2) 输入百分制成绩后要判断该成绩的合理性,对不。

3、合理性的成绩应输出出错信息。If 语句 s=input(please input the score:);if s=90&s=80&s=70&s=60&s0&s bbbplease input the score:94rank =A bbbplease input the score:75rank =C bbbplease input the score:-3rank =wrong socre bbbplease input the score:456rank =wrong socreSwitch 语句 score=input(please input the score:); switch 。

4、floor(score/10)case9,10rank=A;case8rank=B;case7rank=C;case6rank=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:94rank =A cccplease input the score:45rank =E3、硅谷公。

5、司员工的工资计算方法如下:(1)、工作时数超过 120 小时者,超过部分加发15%。(2)、工作时数低于 60 小时者,扣发 700 元。( 3)、其余按每小时 84 元计发。 试编程按输入的工号和该号员工的工时数,计算应发工资。 number=input(please input work number:); h=input(please input work hours:);if h120wage=120*84+(h-120)*84*1.15;elseif h dddplease input work number:01please input work hours:74 wage =62。

6、16 dddplease input work number:02please input work hours:53 wage =3752 dddplease input work number:03please input work hours:135 wage =115294、设计程序,完成两位数的加、减、乘、除四则运算,即产生两个两位随机整数,再输入 一个运算符号,做相应的运算,并显示相应的结果。 x=input(please input a sign:,s);x1=round(rand(1)*90+10);x2=round(rand(1)*90+10);if x=+answer=x1。

7、+x2;elseif x=- answer=x1-x2;elseif x=* answer=x1*x2;elseif x=/answer=x1/x2;endx1x2answer eee please input a sign:+ x1 =83 x2 =11 answer =94 eee please input a sign:-x1 =23 x2 =28 answer =-55、建立5X 6矩阵,要求输出矩阵第n行元素。当n值超过矩阵的行数时,自动转为输出矩阵的最后一行元素,并给出出错信息。 x=ra nd(5,6);n=input(please input n:);if n0&n5;y=x(5,:);disp(wrong n);elseif n eeeplease input n:4y =0.9383 0.2789 0.4787 0.9222 0.9238 eeeplease input n:7wrong ny =0.4397 0.1121 0.9442 0.5744 0.1443 eeeplease input n:-3y =wrong n0.59450.3099y。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值