CJCoding With Joseph
15free / daySign inCreate account

Sum of First N Odd Numbers

Read 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
Topics:
Loops
📥 Auto-Input:
4
This input is automatically fed to your program's stdin
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.