Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts

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();
}
Read more »

Saturday, February 14, 2015

C program to find sum of series 1 2 3 2 5 2 n 2

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

void main()
{
clrscr();
int n,i;
long sum=0;

cout<<"1^2+3^2+5^2+......+n^2

 Enter Value of n:";
cin>>n;

for(i=1;i<=n;i+=2)
sum+=(i*i);

cout<<"
Sum of given series is "<<sum;
getch();
}
Read more »