← Back to Loops
Question 289
Sum of First N Odd Numbers
Sum of First N Odd Numbers
Read an integernfrom standard input and print the sum of the firstnodd numbers (1 + 3 + 5 + ...), with no trailing newline. For example, if the input is4, the sum of1 + 3 + 5 + 7is exactly what is shown in Expected Output. Track the current odd number and add2to 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.