Sum of First N Numbers Problem

Sum of First N Numbers Problem — ExecCode School DSA Practice

Solve the Sum of First N Numbers problem on ExecCode. Free online school DSA practice in Numbers & Math Logic. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given a non - negative integer n, return the sum of all positive integers from 1 to n. Formula: Sum(n) = n + (n - 1) + (n - 2) + ... + 1 Example: Sum(3) = 3 + 2 + 1 = 6

Examples

Input n = 3; Output 6. Input n = 5; Output 15. Input n = 10; Output 55

Constraints

0 <= n <= 100 n is an integer

Practice Sum of First N Numbers free on ExecCode. Browse DSA problems, topic map, and placement guides.