C Program to Calculate sum of first N natural numbers

Spread the love


This Program accepts one Integer from user and stores that value into the variable n.  Then calculates the Sum of first n numbers.

Formula to calculate Sum of first N natural Numbers :

Program :

  1. #include<stdio.h>
  2. int main()
  3. {
  4.         int i,sum,n;
  5.         printf(“Enter Number : “);
  6.         scanf(“%d”,&n);
  7.         sum = 0;       
  8.         for(i=1; i<=n; i++)
  9.         {
  10.                 // This loop will add each number to sum variable.
  11.                 sum = sum + i;
  12.         }
  13.         printf(“The Sum of First %d natural numbers is : %d n, n, sum);
  14.         return 0;
  15. }

Output :

Related Programs:

Venkatesh Macha

Hi Guys, I am Venkatesh Macha. I am a programmer and an Open Source enthusiast, Presently working as a Software Engineer. Apart from that, I love to explore new technologies and things.

You may also like...

1 Response

Leave a Reply