Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
using while loop to sm up elements
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Use a while loop to sum up the elements of a vector (starting with the first element)
until the sum is bigger than 14. Print out a message if the sum never gets bigger than 14.
Otherwise, print out the sum. Both print statements should happen AFTER the loop has
finished. Test the while loop with x=[2.2 4 9 7 8] and x=[-4 5 3 -5 1 -10 1 8].
Hint: A simple way to swap from one x to the other is to declare both assignments
and just comment one out. Then you can demonstrate both to the TA without having to
make a copy of the while loop. eg
%x =[2.2 4 9 7 8];
x=[-4 5 3 -5 1 -10 1 8]
Hint: You will need an index variable to tell if you’ve gone past the end of the
array.
0 Kommentare
Antworten (0)
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!