Write a C program to find the sum of all natural numbers between 1 to n using for loop. How to find sum of natural numbers in a given range in C programming. C program to find sum of natural numbers withing given interval using loop.

Input n: 10

Output sum of natural number 1-10: 55

Also don't forget to check this program using recursive programming technique - C program to find sum of natural numbers within given interval using recursion.

Happy coding ;)

**Example:**Input n: 10

Output sum of natural number 1-10: 55

### Required knowledge

Basic C programming, For loop### Program to find sum of natural numbers

/** * C program to find sum of natural numbers between 1 to n */ #include <stdio.h> int main() { int i, n, sum=0; /* Reads any number from user */ printf("Enter any number to find sum of first n natural numbers: "); scanf("%d", &n); /* * Calculates sum of all natural numbers */ for(i=1; i<=n; i++) { sum += i; } printf("\nSum of first %d natural numbers = %d", n, sum); return 0; }

**Note:**sum += i is similar to sum = sum + i. You can any of them to find sum.

Output

Enter any number to find sum of first n natural numbers: 10

Sum of first 10 natural numbers = 55

Sum of first 10 natural numbers = 55

Also don't forget to check this program using recursive programming technique - C program to find sum of natural numbers within given interval using recursion.

Happy coding ;)

### You may also like

- Loop programming exercises index.
- C program to print all natural numbers between 1 to n.
- C program to find sum of even numbers between 1 to n.
- C program to find sum of odd numbers between 1 to n.
- C program to find sum of first and last digit of any number.
- C program to find sum of elements of an array.
- C program to print all alphabets from a to z.
- C program to print ASCII values of all characters.
- C program to print all even numbers between 1 to 100.
- C program to print all odd numbers between 1 to 100.
- C program to find HCF(GCD) of two numbers.
- C program to find LCM of two numbers.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).