至少几十行的程序,你知道还就5分,要不是我有现成的,真的没人会给你写。
function score2grade(varargin)
%作者:victoriajll 日期:2011.10.14
%特点:
%有较强的容错能力,功能比较完善。
%使用方法:
%1.没有输入参数:即直接在命令窗口输入函数名score2grade运行,会提示输入;
%2.有输入参数:支持
标量和向量输入,例如score2grade(88)
%或者score2grade([-12 34 65 75 86 98 120])
if nargin==0
score=input('请输入学生成绩:');
while isempty(score)
score=input('请输入学生成绩:');
end
else
score=varargin{1};
end
grade=judge(score);
for i=1:length(score)
fprintf('%4d\t%s\n',score(i),grade{i})
end
end
function grade=judge(score)
n=length(score);
grade=cell(1,n);
for i=1:n
if score(i)>100||score(i)<0
grade{i}='错误';
continue
end
if score(i)>=90&&score(i)<=100
grade{i}='A';
continue
end
if score(i)>=80&&score(i)<90
grade{i}='B';
continue
end
if score(i)>=70&&score(i)<80
grade{i}='C';
continue
end
if score(i)>=60&&score(i)<70
grade{i}='D';
continue
end
if score(i)>=0&&score(i)<60
grade{i}='E';
end
end
end
本回答被提问者和网友采纳