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

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: