初学matlab,有几道程序设计的题不会。急需帮助!

2024-11-16 05:56:55
推荐回答(1个)
回答1:

n=input('输入学生个数:');
score=zeros(n,3);
aver=zeros(n,1);
levels=zeros(1,5);
lname={'A','B','C','D','E'};
for i=1:n
for j=1:3
score(i,j)=input(sprintf('输入第%d名学生第%d门课成绩',i,j));
end
aver(i) = (score(i,1) + score(i,2) + score(i,3)) / 3;
if aver(i) >= 90
l = 1;
else if aver(i) >= 80
l = 2;
else if aver(i) >= 70
l = 3;
else if aver(i) >= 60
l = 4;
else
l = 5;
end
end
end
end
levels(l) = levels(l) + 1;
disp(strcat('该学生成绩等级为',lname{l}));
end
for i=1:5
fprintf(1,'%4c',lname{i});
end
disp(' ');
for i=1:5
fprintf(1,'%4d',levels(i));
end
disp(' ');