Use while loop to print out the powers of 2 less than 1000. - C++ Statement

C++ examples for Statement:while

Description

Use while loop to print out the powers of 2 less than 1000.

Demo Code

#include <iostream> 
#include <cmath> 
using namespace std ; 

int main(){//from   w w w.j  a  v a  2s  . c  o  m

   int count = 0; 
   int currentPower = 1; 
   while ( currentPower <1000) { 
       cout << "2^" << count << "="; 
       cout << currentPower ; 
       cout << "\n"; 
       currentPower *= 2; 
       count ++; 
   } 
   return 0;
} 

Result


Related Tutorials