还剩1页未读,继续阅读
文本内容:
实验四程序设计Matlab
一、实验目的与要求
1.熟悉程序设计思想
2.掌握伪代码的编写方法
3.掌握分支语句和循环结构的用法
二、实验内容
1.输入一个百分制成绩,要求输出成绩等级A、B、C、D、E,其中90-100为A,80-89为B,70-79为C,60-69为D,60分以下为E要求1分别用if语句和switch语句实现;2应对输入的成绩进行合理性判断,对不合理的成绩应输出错误信息
2.编程实现一个九九乘法表,并屏幕显示出来,3,计算the dayof year年积日,the dayof year是指这一年已经逝去的天数包括当天在平年中,它的取值范围为1到365,在闰年中,它的取值范围1到366编写一个MATLAB程序,输入年、月、日,输出为对应的the of yearo
三、实验过程和结果
1.输入一个百分制成绩,要求输出成绩等级A、B、C、D、E,其中90-100为A,80-89为B,70-79为C,60-69为D,60分以下为E要求1分别用if语句和switch语句实现;If语句成绩;x=inputif x=90x=100dispW;elseif x=80x=89dispB;elseif x=70x=79dispC;elseif x=60x=69dispD;else dispE;end成绩85B.switch语句,成绩x=input switchxcase num2cell90:100dispW;case num2cell80:89dispB;case num2cell70:79dispC;case num2cell60:69dispCD;成绩otherwise dispE;end85B2应对输入的成绩进行合理性判断,对不合理的成绩应输出错误信息命令行窗口x=input成绩;if x100||x0dispwrong input,;elseswitch xcase num2cell90:100dispA;case num2cell80:89dispB;case num2cell70:79dispC;casenum2cell60:69dispD;otherwise dispE;end end成绩101wrong inputA»
2.编程实现一个九九乘法表,并屏幕显示出来,如下所示:for i=l:9for j=l:ifprintf,%dx%d=%d,,j,i,i*j;ifj~=ifprintf;end endfprintf\n;end1x1=11x2=22x2=41x3=32x3=63x3=91x4=42x4=83x4=124x4=161x5=52x5=103x5=154x5=205x5=251x6=62x6=123x6=184x6=245x6=306x6=361x7=72x7=143x7=214x7=285x7=356x7=427x7=491x8=82x8=163x8=244x8=325x8=406x8=487x8=568x8=641x9=92x9=183x9=274x9=365x9=456x9=547x9=638x9=729x9=
813.计算the dayof year年积日,the dayofyear是指这一年已经逝去的天数包括当天在平年中,它的取值范围为1到365,在闰年中,它的取值范围1到366编写一个MATLAB程序,输入年、月、日,输出为对应的the ofyearo命令行窗口y=input年;m二input C月’;d=input日’;sum=O;a=[31,28,31,30,31,30,31,31,30,31,30,31];b=L31,29,31,30,31,30,31,31,30,31,30,31];ify0||m0||d0||m12||d31fprintfwrong input;elseif mody,400==0||mody,100=0mody,4==0for i=l:m-lsum=sum+bi;endif dbm fprintfwrong input;else fprintfC%d,,sum+d;endelsefor i=l:m-l sum=sum+a⑴;endif dbm fprintfwrong input;——else fprintfC与d,sum+d;V endendend年2020月8Hllfx224»
四、实验报告内容
1.熟悉程序设计思想
2.掌握伪代码的编写方法
3.掌握分支语句和循环结构的用法
4.书写实验报告时要结构合理、层次分明、在分析描述的时候,需要注意语言的流畅。
个人认证
优秀文档
获得点赞 0