还剩4页未读,继续阅读
文本内容:
实验四程序设计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-input,成绩);if x=90x=100disp(,A);elseif x=80x=89dispC B,);elseif x=70x=79disp(C);elseif x=60x〈=69disp(,D);else disp(E);end成绩;x=input ifx=90x=100dispA1;elseif x=80x=89dispB;elseif x=70x:79dispC;elseif x=60x=69dispD;else dispE;end成绩85B.switch语句x=input,成绩;switch xcase num2cell90:100dispC A;case num2cell80:89dispC;case num2cell70:79disp C;case num2cell60:69dispC D5;otherwisedisp E;end成绩x=inputfswitch xcase num2cell90:100dispCA;case num2cell80:89dispCB;case num2cell70:79dispC;case num2cell60:69dispCD;otherwisedispCE;end成绩85B2应对输入的成绩进行合理性判断,对不合理的成绩应输出错误信息x=input C成绩;ifx100||x0disp Jwrong input;elseswitch xcase num2cell90:100dispA;case num2cell80:89dispC B,;case num2cell70:79dispC C;case num2cell60:69disp,D,;otherwisedisp5E;end end成绩;x=input ifx100||x0dispwronginput;elseswitch xcasenum2cell90:100dispA;casenum2cell80:89dispB;casenum2cell70:79dispC;casenum2cell60:69dispD;otherwisedispCE;endend成绩120wrong input
2.编程实现一个九九乘法表,并屏幕显示出来,如下所示:for i=l:9for j=l:ifprintfC%dx%d=%d,,j,i,i*j;fprintf;endendfprintf\n,;end for i=l:9for j-l:ifprintf%dx%d=%d,j,i i*j;lifj~=ifprintf1;endendfprintf\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 ofyearoy=input年;m=input月’;d=input日;sum=0;a=[31,28,31,30,31,30,31,31,30,31,30,31];b=[31,29,31,30,31,30,31,31,30,31,30,31];ify0||m0||d0||m12||d31fprintf C wrong input;elseif mod y,400=0||mod y,100=0mody,4=0fori=l:m-l〜sum=suni+b i;endif dbm fprintfC wronginput;else fprintf%d,sum+d;endelsefor i=l:m-lsum=sum+a⑴;endif dbm fprintfCwronginput;else fprintfC%d,sum+d;endend end年;y=inputf二月’;日m inputd=input sum=0;a=[31,28,31,30,31,30,31,31,30,31,30,31];b=[31,29,31,30,31,30,31,31,30,31,30,31];ify0||m0||d0||m12||d31fprintfwrong input;elseifmody400==0||mody100-=0mody,4==0fort tsum=sum+bi;end1ifdbm fprintfwronginput;;else fprintf%d sum+d;endelsefor i=l:m-lsum=sum+ai;end1ifdbm fprintfwronginput;else fprintfCO^d,sum+d;endendend年2020月5日10131»|
四、实验报告内容
1.熟悉程序设计思想
2.掌握伪代码的编写方法
3.掌握分支语句和循环结构的用法
4.书写实验报告时要结构合理、层次分明、在分析描述的时候,需要注意语言的流畅。
个人认证
优秀文档
获得点赞 0