adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

program in c to calculate the sum of nth natural numbers.

Program in C to calculate the sum of nth natural numbers.


#include<stdio.h>
#include<conio.h>
 void main()
  {
      int n,i,sum=0;
      printf("Enter a number:-");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
       sum+=i;
      }
      printf("Sum of %d natural numbers = %d",n,sum);
      getch();
  }
Output :-





Post a Comment

0 Comments