C Program to Find the Sum of First N Natural Numbers

Find the Sum of first N natural numbers

A Natural number is a same as Counting number.They are used to Count the numbers of real physical object.

Natural number is start from 1 and go on infinite.

The positive numbers 1, 2, 3… are known as natural numbers.

Example: Natural number={1,2,,4,5,6,…….}.

Formula for Sum of First  N natural numbers is : n(n+1)/2.

If you want to add first 5 Natural number then we find the Sum of 1+2+3+4+5 =15.

 

sum of n natural number

Implementation of Sum of first N natural number

First of all we will initialize the variables sum and n ,then we will print the n natural number .

and Now we will use the formula of find the sum of N natural number is Sum=(n*(n+1))/2.

and finally print the sum .

Code of Find the sum of N natural number


#include
   int main()
{
   int sum=0,n;
    printf("enter the first N natural number\n");
    scanf("%d",&n);
sum=(n*(n+1))/2;
   printf("sum is%d",sum);
}

Output

enter the first N natural number

7

sum is 28