Q:

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

0

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 .

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
 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:

Enter The Number Of Terms 

256

Series I sGiven Below

1 2 4 8 16 32 64 128 256 

Sum Of Above Series Is

511

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program To Print The Series 1 -4 7 -10 . . . .... >>
<< C++ Program To Find Sum Of Given Series 1^2+3^2+5^...