- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
matlab选择结构程序设计答案
实验三 选择结构程序设计
实验目的
掌握建立和执行M文件的方法。
掌握利用if语句实现选择结构的方法。
掌握利用switch语句实现多分支选择结构的方法。
掌握try语句的使用。
实验内容
求分段函数的值。用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 x0x~=-3
y=x*x+x-6;
elseif x=0x5x~=2x~=3
y=x*x-5*x+6;
else
y=x*x-x-1;
end
y
②please input the value of x-5.0
y =
14
aaaaa
please input the value of x-3.0
y =
11
aaaaa
please input the value of x1.0
y =
2
aaaaa
please input the value of x2.0
y =
1
aaaaa
please input the value of x2.5
y =
-0.2500
aaaaa
please input the value of x3.0
y =
5
aaaaa
please input the value of x5.0
y =
19
输入一个百分制成绩,要求输出成绩等级A、B、C、D、E。其中90分~100分为A,80分~89分为B,70分~79分为C,60~69分为D,60分以下为E。要求:
分别用if语句和switch语句实现。
输入百分制成绩后要判断该成绩的合理性,对不合理性的成绩应输出出错信息。
If语句
①s=input(please input the score:);
if s=90s=100
rank=A;
elseif s=80s=89
rank=B;
elseif s=70s=79
rank=C;
elseif s=60s=69
rank=D;
elseif s0s=59
rank=E;
else
rank=wrong socre
end
rank
②
bbb
please input the score:94
rank =
A
bbb
please input the score:75
rank =
C
bbb
please input the score:-3
rank =
wrong socre
bbb
please input the score:456
rank =
wrong socre
Switch语句
①score=input(please input the score:);
switch floor(score/10)
case{9,10}
rank=A;
case{8}
rank=B;
case{7}
rank=C;
case{6}
rank=D;
case num2cell(0:5)
rank=E;
otherwise
rank=wrong score;
end
rank=rank
②
ccc
please input the score:-3
rank =
wrong score
ccc
please input the score:456
rank =
wrong score
ccc
please input the score:94
rank =
A
ccc
please input the score:45
rank =
E
硅谷公司员工的工资计算方法如下:
(1)、工作时数超过120小时者,超过部分加发15%。
(2)、工作时数低于60小时者,扣发700元。
(3)、其余按每小时84元计发。
试编程按输入的工号和该号员工的工时数,计算应发工资。
①number=input(please input work number:);
h=input(please input work hours:);
if h120
wage=120*84+(h-120)*84*1.15;
elseif h60
wage=h*84-700;
else
wage=h*84;
end
wage
② ddd
please input work number:01
please input work hours:74
wage =
6216
ddd
plea
文档评论(0)