C++ Program to print given series:1 2 4 8 16 32 64 128

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i;

for(i=1;i<=128;i*=2)
cout<<i<<” “;
getch();
}

25 thoughts on “C++ Program to print given series:1 2 4 8 16 32 64 128

  1. Panjaj Mishra

    how can i print this series -1 2 -4 8 -16 32 -64 128………..

    Reply
  2. Neeraj Mishra

    @pankaj you can print this series by multiplying i by -1 each time like this…….

    for(i=i;i<=128;++i)
    i*=(-1);

    just try it you will definitely get your result……..

    Reply
  3. Neeraj Mishra

    @Rajendra

    for(int i=1;i<5;++i)
    {
    for(int j=1;j<i;j++)
    cout<<j;
    cout<<"n";
    }

    Reply
  4. phanikumar

    how can i copy one file content into another using command line arguments ??

    Reply
  5. Manish Jain

    how can i print tis series 1,2,4,8,16,32,64,128……………n using function

    Reply
  6. Neeraj Mishra

    @mansi

    void sum(int n)
    {
    for(int i=1;i<=n;i*=2)
    cout<<i<<" ";
    }

    just call this function from void main()………

    Reply
    1. zahid

      #include
      using namespace std;
      int main()
      {
      int i;

      for(i=64;i>=2;i/=2)
      cout<<i<<" ";
      return 0;
      }

      Reply
  7. mohammad zarrar

    Write a program that takes an integer as an input from user and prints if it is a prime or composite number.Also ask to run again program or not (Do-While) plz solve this programmm

    Reply
  8. rabbi

    how can i make a program like 2 4 6 8 10 ………N using if statements.Pls solve my code.I think my code is ok.but when i run this program .the console just show me 2.pls solve it.

    #include
    int main()
    {
    int j,product;
    j=2;
    product=1;

    if(j<=10)
    {
    product=product*j;
    printf("%d\n",product);
    j+=2;
    }

    }

    Reply
    1. Admin Post author

      You can’t to do this using only if, you have to use loops also. Just follow above program.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *