Sunday, February 15, 2015

C program to find sum of series 1 2 3 n


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

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,n,sum=0;
cout<<"1+2+3+......+n";
cout<<"
Enter the value of n:";

cin>>n;

for(i=1;i<=n;++i)
sum+=i;
cout<<"
Sum="<<sum;

getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.