For loop nested in while loop problem
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have written a while loop that is supposed to determine the value of the parameter "n" for "a" to exceed the value 300. I know "n" should be 17, but I'm getting a value of 4 instead. Does anyone see the problem?
The code is as follows:
a = 10;
k = 0.5;
n = 2;
while a < 300
for m = 1:5
a = a + (a*k) + n;
end
n = n + 1;
end
0 commentaires
Réponse acceptée
Plus de réponses (1)
Azzi Abdelmalek
le 18 Oct 2013
Modifié(e) : Azzi Abdelmalek
le 18 Oct 2013
Why are you using a for loop from 1 to 5? You are not supposed to increment n instead of m?
2 commentaires
Anthony
le 18 Oct 2013
matlab is telling you the correct answer. iterating the following for 5 times will give a pretty large number.
a = a + (a*k) + n;
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!