How can I write allpowers of 2 from 2^0 up to 2^12 in C++ ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aithusa
    New Member
    • Mar 2012
    • 1

    #1

    How can I write allpowers of 2 from 2^0 up to 2^12 in C++ ?

    How can I write all powers of 2 from 2^0 up to 2^12 using while loop statement in C++? on the screen it must be seem like 2^0 2^1 2^2 2^3 2^4.....2^12.
    Can you help me please about this code.Thanks a lot.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Use the pow() function inside a loop.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      or just a loop (without the pow() function) like this:
      Code:
      do
       {
        cout<<"2^"<<y<<"\t"<<x<<endl;
        x*=2;
        y++;
        }while(y<13);

      Comment

      Working...