- disp()
- for
- input()
- plus()
How do i write algorithms
7 次查看(过去 30 天)
显示 更早的评论
Develop M-file that can do followings
- Ask you starting and final number to add up (e.g., ni=0, nf=300)
- Display the total of the numbers (e.g., sum=0+1+2+....+300)
采纳的回答
Raj
2019-4-29
Many ways of doing this problem. Below is one way:
ni=input('Enter initial value:');
nf=input('Enter final value:');
A=zeros(nf-ni,1);
A(1)=ni;
for i=2:size(A)+1
A(i)=A(i-1)+1;
end
Sum=sum(A)
1 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!