Compute the order of magnitude of an integer : While : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » While »

 

Compute the order of magnitude of an integer









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Compute the order of magnitude of an integer 
 
using System; 
 
public class WhileDemo {   
  public static void Main() { 
    int num; 
    int mag; 
 
    num = 435679; 
    mag = 0; 
 
    Console.WriteLine("Number: " + num); 
 
    while(num > 0) { 
      mag++; 
      num = num / 10; 
    }; 
 
    Console.WriteLine("Magnitude: " + mag); 
  }   
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» While