Question
Calculate sum of First 10 Natural Numbers using for loop in C Language.
Solution
✔ Verified
This C program calculates the sum of the first 10 natural numbers using a for loop.
Natural numbers start from 1 and go on incrementally.
In this program, a loop runs from 1 to 10, and in each iteration, the current number is added to a sum variable. By the end of the loop, the variable holds the total sum of numbers from 1 to 10.
This example helps beginners understand how loops and accumulators work together to perform repeated addition in C programming.
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum += i;
}
printf("Sum = %d\n", sum);
return 0;
}Output:--
Sum of first 10 Natural numbers is = 55Click here to download practice questions on
For Loop In C