还剩3页未读,继续阅读
文本内容:
实验四程序设计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=89disp,B,;elseif x=70x=79disp,C;elseif x=60x=69dispC D;else dispCE;end成绩;x=inputif x=90x=100dispA;elseif x=80x=89dispB;elseif x=70x=79dispC;elseif x=60x=69dispD;else dispE;end成绩85Bswitch语句x二input成绩;switch xcase num2cell90:100disp,A;case num2cell80:89dispB;case num2cell70:79disp,C,;case num2cell60:69disp D;otherwisedisp E;end x=input C成绩;switch xcase num2cell90:100dispC A;case num2cell80:89dispC B;case num2cell70:79dispC C;case num2cell60:69dispC D;otherwisedispC E,;end成绩70CA»2应对输入的成绩进行合理性判断,对不合理的成绩应输出错误信息x=input成绩;ifx100||x0disp5wrong input;elseswitch xcase num2cell90:100dispC A;case num2cell80:89dispC B;case num2cell70:79disp C;case num2cell60:69disp D;otherwise disp,;endend x=input成绩’;if x100||x0disp C wrong input;elseswitch xcasenum2cell90:100disp CA’;casenum2cell80:89dispB;casenum2cell70:79dispC;casenum2cell60:69disp,D;otherwisedisp,E;endend成绩101wrong inputA»
2.编程实现一个九九乘法表,并屏幕显示出来,如下所示:for i=l:9for j=l:ifprintf%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;if j~=ifprintf;endendfprintf C\n;end1x1=11x2=22x2=41x3=32x3=63x3=91x5=53x5=154x5=205x5=253x6=184x6=245x6=306x6=361x6=63x7=214x7=285x7=356x7=423x8=244x8=325x8=406x8=481x8=83x9=274x9=365x9=456x9=541x9=91x4=42x4=83x4=124x4=163,计算the2x d5a=y1o0fyear(年积日),the dayof year是指这一年已经逝去的天数(包括当天)2x在6=平12年中,它的取值范围为1到365,在闰年中,它的取值范围1到366编写一个M2Ax T7=L1A4B程序,输入年、月、日,输出为7x对7=应49的the ofyeary=input2年x8=16;7x8=568x8=64m=input2月x9’=18;d=input日;sum=0;7x9=638x9=729x9=81a=[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 Cwrong input;elseif mod y,400=0||mody,100~=0mody,4==0for i=l:m-lsum=sum+b⑴;endif db m fprintf Cwrong input;else fprintf%d,sum+d;endelsefor i=l:m-lsum=sum+ai;end ifdbmfprintfCwrong input;else fprintfC%d,,sum+d;endendend y«input年;m=input月d=inputB;sum=0:a=i31,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 wrong input;elseif mody,400—01|mody,100*=0mody,4==0fori=l:m-1sum=sua+bi:endifdbm fprintfwronginputelse fprintf%d»suit+d;endelsefor i=l:m-1sum=sua+a⑴endifdbm fprintfwronginputelse fprintf%d,siuH-d;endendend年2020月5日101131〉|
四、实验报告内容
1.熟悉程序设计思想
2.掌握伪代码的编写方法
3.掌握分支语句和循环结构的用法
4.书写实验报告时要结构合理、层次分明、在分析描述的时候,需要注意语言的流畅。
个人认证
优秀文档
获得点赞 0