โ Back to Loops
Question 219
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: 16 Track the current odd number and add2to it each pass.
Expected Output:
16
Topics:
Loops
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.