CJCoding With Joseph

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:

16

Track the current odd number and add 2 to it each pass.

Expected Output:

16
Topics:
Loops
๐Ÿ“ฅ Auto-Input:
4
This input is automatically fed to your program's stdin
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.