C Program to Find the Sum of First N Natural Numbers

sum of first n natural number in c

Find the Sum of first N Natural Numbers

In this article we will see C Program to 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 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.

Algorithm

  • Step 1. Start
  • Step 2. Enter a number (N).
  • Step 3. Use formula to calculate the sum of N natural number || Sum=(n*(n+1))/2.
  • Step 4. Print sum of N Natural Number.
  • Step 5. Stop
C program to find sum of first n natural number

C code

#include<stdio.h>
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);
    return 0;
}

Output

Enter the first N Natural Number : 7
Sum is 28