How do i write algorithms

6 vues (au cours des 30 derniers jours)
Antwone Goodwyn
Antwone Goodwyn le 29 Avr 2019
Commenté : Walter Roberson le 30 Avr 2019
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)
  1 commentaire
Walter Roberson
Walter Roberson le 29 Avr 2019
  • disp()
  • for
  • input()
  • plus()

Connectez-vous pour commenter.

Réponse acceptée

Raj
Raj le 29 Avr 2019
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 commentaire
Walter Roberson
Walter Roberson le 30 Avr 2019
We do not recommend posting complete solutions to homework problems.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by