11/16/2015

C++ Program To Print And Find Sum Of Series 1+2+4+8+16+32+. . . N

Problem :- Write A C++ Program To Find Sum Of Given Series 1+2+4+8+16+32+.....n

Logic :- Logic is very simple you need to use one for loop and initialize with 1 and run into numbers of terms condition and increase by multiply of condition like 
i*=2 and print the value of i .
or sum=sum+i; this statement print the sum of the series .

Try Yourself  C++ Program To Find Sum Of Series 1^2+3^2+5^2+. . . . n^2

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadav
int i,n,sum=0;
cout<<"Enter The Number Of Terms \n";
cin>>n;
cout<<"\nSeries I sGiven Below\n\n";
for(i=1;i<=n;i*=2)
{
sum+=i;
cout<<i<<" ";
}
cout<<"\n\nSum Of Above Series Is\n";
cout<<sum <<endl;;
return 0;
}

Output:-
C++ Program To Find Sum Of Series 1+2+4+8+16+32+. . . N

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment