My Function is supoosed to return 55 when i call it with 10 based off of pyramid sum. However my function gives me 20. Please help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alyssa Lakatos
am 30 Sep. 2017
Kommentiert: Alyssa Lakatos
am 1 Okt. 2017
function CountUpToN(N)
i=0;
for i=1:N
i=i+N
disp(i)
end
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 30 Sep. 2017
Bearbeitet: Les Beckham
am 30 Sep. 2017
The main problem with this code is that you are using the same variable for the loop index and for accumulating your result. The for loop will replace i with the next loop index each time through the loop, thus obliterating your accumulated result.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!