Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Sum Of First N Natural Numbers

Easy Acceptance 60% Points 20

You are given a positive integer n. Your task is to find and print the sum of the first n natural numbers, that is, add all numbers starting from 1 up to n and return the final sum.

The result should be displayed as a single integer.

Examples
Example 1

Example 1

Input: 5

Output: 15

Explanation: 1+2+3+4+5 = 15

Example 2

Example 2

Input: 10

Output: 55

Explanation: 1+2+3+4+5+6+7+8+9+10 = 55

Constraints
  • 1 < n < 106
  • n is a positive integer.
Topics
Recursion
Companies
Microsoft Samsung Walmart
Added 04 Feb 2026 60% acceptance
Ln 1, Col 1Sign in to save your code
Sample inputs for this problem are shown in the examples.