Sum of First N Odd Numbers
mediumQuestion 289Read an integer n from standard input and print the sum of the first n odd numbers (1 + 3 + 5 + ...), with no trailing newline. For example, if the input is 4, the sum of 1 + 3 + 5 + 7 is exactly what is shown in Expected Output.
Track the current odd number and add 2 to it each pass.
Expected output
16= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics
Loops
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.