Recursive Sum to N
Recursive Sum to N
EasyRecursion66% accepted
Compute the sum 1 + 2 + ... + N using recursion instead of a loop. The key insight: sum(N) = N + sum(N-1), and sum(0) = 0. This is your first introduction to recursive thinking — solving a problem by reducing it to a smaller version of itself.
Approach
Given N, compute and print the sum 1+2+...+N using recursion.
Input
1
Output
1
More Recursion problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards