Problem Statement
Write a C program that calculates the sum of all natural numbers from 1 to n, where n is a positive integer provided by the user.
For example, if n = 5, the sum would be 1 + 2 + 3 + 4 + 5 = 15.
Use a loop to solve this problem.
DEMO-C-32 • Programming in C
Write a C program that calculates the sum of all natural numbers from 1 to n, where n is a positive integer provided by the user.
For example, if n = 5, the sum would be 1 + 2 + 3 + 4 + 5 = 15.
Use a loop to solve this problem.
The input consists of a single positive integer n (1 ≤ n ≤ 1000).
Output a single integer representing the sum of all natural numbers from 1 to n.
Submit runs every public testcase in this browser. Results and code never leave this device.
5
15
1
1
100
5050
7
28
C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.
/workspace/question