Compute integer powers of 2 : While : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » While »

 

Compute integer powers of 2









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Compute integer powers of 2. 
 
using System; 
 
public class Power {   
  public static void Main() { 
    int e; 
    int result; 
 
    for(int i=0; i < 10; i++) { 
      result = 1; 
      e = i; 
 
      while(e > 0) { 
        result *= 2; 
        e--; 
      } 
 
      Console.WriteLine("2 to the " + i +  
                         " power is " + result);        
    } 
  }   
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» While