Sum of n Natural Numbers in C

Sum of n Natural Numbers in C

Here you will learn about the natural numbers and get the program code to calculate Sum of n Natural Numbers in c programming. We will create this program by using 5 different ways with loops, functions, and recursion in C Programming.

What is Natural Number?

A natural number is any positive integer, or whole number, greater than zero. for examples :- 1, 2, 3, 4, 5, 6…… and so on.

sum of n natural numbers in c

 

Sum of n Natural Numbers Formula?

sum = n(n+1)/2

where n is number of terms

For example:
n=10;

sum = 10(10+1)/2

sum = 10(11)/2

sum = 55

 

 Different 5 Ways to find Sum of n Natural Numbers in C

Here, we will do this program using 5 different ways like using while loop, do-while loop, for loop, functions, and  recursion.

Using while loop

Output

natural sumber sum

 

Using do while loop

Output

natural sumber sum

 

Using for loop

Output

natural sumber sum

 

Using functions

Output

natural sumber sum

 

Using recursion

Output

natural sumber sum

 

 

 

Check out our other C programming Examples

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top