Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
New to matlab, need help with problem..
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am suppose to create a loop to calculate the sum 1+2+3+...+300. Display the total after each 50 (i.e. 50, 100, 150 …) I know I need an if statement in my for loop but have no idea what to do. This is what I have thus far..
Total = 0;
for z = 1:299
Total = Total + z*(z+1)
if z(50 == 0)
0 Kommentare
Antworten (2)
James Tursa
am 11 Dez. 2017
Bearbeitet: James Tursa
am 11 Dez. 2017
Good start. Thank you for posting your code. Some help:
- Have the top value of your loop be 300, not 299
- Have the Total simply add in z, not z*(z+1)
- Use the mod function in your if-test. E.g.,
if mod(z,50)==0
0 Kommentare
Mohammed Safwat
am 11 Dez. 2017
Bearbeitet: James Tursa
am 11 Dez. 2017
1 Kommentar
James Tursa
am 11 Dez. 2017
Put a semi-colon at the end of a line to suppress the screen output. E.g.,
Total = Total + z;
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!