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();
}

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

  1. 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
  2. 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
  3. 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 *