Matlab基础问题 急!急求答案
来源:学生作业帮助网 编辑:作业帮 时间:2024/04/24 21:10:15
Matlab基础问题 急!急求答案
Matlab基础问题 急!
急求答案
Matlab基础问题 急!急求答案
1.在Matlab下输入edit multiplication.m,再将下面两行%之间内容复制进去,保存退出(实际上就是生成multiplication.m文件)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function multiplication
a=input('Which multiplication table?');
for i=1:12
disp([num2str(i),'×',num2str(a),'=',num2str(i*a)])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2.在Matlab下输入edit multiplication2.m,再将下面两行%之间内容复制进去,保存退出(实际上就是生成multiplication2.m文件)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function multiplication2
while 1 %loop
a=input('Which multiplication table?');
if =floor(a) %check integer
disp('Please enter an integer number only.');
elseif a>12||aAns %too big
disp('Your guess is too high.');
elseif x
m=input('Which multiplication tabel? ');
for j=1:12;
k=j*m;
fprintf('%d x %d = %d\n',j,m,k);
end
results:
Which multiplication tabel? 5
1 x 5 = 5
2 x 5 = 10
全部展开
m=input('Which multiplication tabel? ');
for j=1:12;
k=j*m;
fprintf('%d x %d = %d\n',j,m,k);
end
results:
Which multiplication tabel? 5
1 x 5 = 5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
10 x 5 = 50
11 x 5 = 55
12 x 5 = 60
收起