Working with Array.cpp array calculation.Help please.Why this code output wrong?? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Working with Array.cpp array calculation.Help please.Why this code output wrong??

https://code.sololearn.com/c20EhfNLke8w/?ref=app

12th Feb 2021, 8:44 AM
Shubham Dhyani
Shubham Dhyani - avatar
4 Antworten
+ 5
What exactly? If output, then this is explanation of output: 1) adding 1 to 0, printing "1"; 2) adding 2 to 1, printing "3"; 3) adding 3 to 3, printing "6"; 4) adding 4 to 6, printing "10"; 5) adding 5 to 10, printing "15"; 6) adding 6 to 15, printing "21"; 7) adding 7 to 21, printing "28"; 8) adding 8 to 28, printing "36". Final output: "1361015212836" ("1" + "3" + "6" + "10" + "15" + "21" + "28" + "36"). Note: try placing `cout<<x;` outside the "for" curly brackets to print only the final value (36).
12th Feb 2021, 8:54 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 8
Shubham Dhyani , as the output expression is placed inside the for loop, it will be executed in each iteration. BTW, your description of ".. why this code is not working? ..." does not really help, because this can mean anything.
12th Feb 2021, 10:15 AM
Lothar
Lothar - avatar
0
Thanks to give time to solve my problem
12th Feb 2021, 9:50 AM
Shubham Dhyani
Shubham Dhyani - avatar
0
But why this happens if inside curley bracket
12th Feb 2021, 9:59 AM
Shubham Dhyani
Shubham Dhyani - avatar