Signup/Sign In

C++ Program To Find Sum Of Series 1 + 2 + 4 + 8 + 16 + 32 + . . . . . . . . n

Here, in this tutorial, we will be seeing how to write the program for the given pattern and at the end print the resultant sum of the series formed for the input number of terms by the user.

We can have two different approaches to write the program but based on the time complexity the second method will be much better as it will take a constant amount of time even for the large input whereas the first one will become a little bit slow for higher inputs.

C++ Program For The Sum of Series


void main()
int i,n,sum=0;
cout<<“\nEnter the value of n:”;


Enter the value of n: 3


There can be more than these methods to solve the same problem but the second one will be better than all since it takes a constant amount of time.

About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.