Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

5 Dec 2012

C program to print sum of series 1+2+3+..+n


#include<stdio.h>
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: