Program to print given series:1 2 4 8 16
Here you will get the source code of C++ program to print given series:1 2 4 8 16, 32… upto n terms.
For Example:
1 2 4 8 16 32 64 128…. n
Example of C++ Program to print given series:1 2 4 8 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> using namespace std; int main() { int n,i=1,sum=1; cout<<"\nEnter the value of n : "; cin >> n; cout<<sum; while(i<=n) { sum=sum*2; i++; cout<<" "<<sum; } return 0; } |
Output
Enter the value of n : 12
1 2 4 8 16 32 64 128 256 512 1024 2048 4096
Other Similar Programs
C++ program to find sum of series 1+1/2+1/3…+1/100
C++ program to find sum of series 1 + 2 + 3 +……+ n
Check out our other C++ programming Examples