Monday 20 March 2017

Sum of Series 1+2+3+..+n

Program :

#include
void main()
{
  int sum=0,i,n;
  printf("\n>>> C Program to print Sum of Series 1+2+3+..+n <<<\n");
  printf("\n Enter the number of terms:");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
      sum+=i;
  }
  printf("\n Sum of series upto %d is :%d \n\n",n,sum);

}


Output :




No comments:

Post a Comment