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.
Example 1
Input: 5
Output: 15
Explanation: 1+2+3+4+5 = 15
Example 2
Input: 10
Output: 55
Explanation: 1+2+3+4+5+6+7+8+9+10 = 55
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.