0

Hi, I wrote the code, but I can't understand why the results go from one to 45, they are from one to 23. Help me figure it out.

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

12th Dec 2018, 6:03 PM
Anton
Anton - avatar
11 Antworten
+ 2
Just keep practicing 😀.
12th Dec 2018, 7:40 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Your question is not clear. Your code print 1, 3 and 5 on a separate lines. What is the purpose of your code ?
12th Dec 2018, 6:29 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
The length of the array you declared is 23 => you have 23 places for numbers in that array. 23 is not the upper limit number of the elements in the array. Then each element is increasing with 2, starting with 1 => your first element. So the output is showing the expected result. Hope it helps you.
12th Dec 2018, 6:44 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
No, it's because you are filling all places in your array. If you count the values they are exactly 23 => the length of the array you declared.
12th Dec 2018, 6:53 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Sorry, a little wrong. Corrected code
12th Dec 2018, 6:35 PM
Anton
Anton - avatar
0
The purpose of my code is to display odd numbers from 1 to 23
12th Dec 2018, 6:37 PM
Anton
Anton - avatar
0
So the value doubles?
12th Dec 2018, 6:47 PM
Anton
Anton - avatar
0
Now I understand 😀 thanks for the help
12th Dec 2018, 6:59 PM
Anton
Anton - avatar
0
You are welcome 😀. You can see the lines I added in your code. https://code.sololearn.com/cYY9tzsfXvvu/?ref=app
12th Dec 2018, 7:29 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Great! That's exactly what I want. Comments help to understand. I should do that too 😀
12th Dec 2018, 7:39 PM
Anton
Anton - avatar
0
I agree 😀
12th Dec 2018, 7:42 PM
Anton
Anton - avatar