Compute the order of magnitude of an integer : While « Language Basics « C# / C Sharp






Compute the order of magnitude of an integer

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


           
       








Related examples in the same category

1.Continue in while
2.Compute integer powers of 2Compute integer powers of 2
3.Display the digits of an integer in reverse orderDisplay the digits of an integer in reverse order
4.Using break to exit a do-while loopUsing break to exit a do-while loop
5.While TesterWhile Tester
6.Do While TesterDo While Tester
7.While SignalWhile Signal
8.While loop to display 1 to 5While loop to display 1 to 5
9.while loop to calculate and display the Fibonacci numbers less than 50while loop to calculate and display the Fibonacci numbers less than 50
10.a do...while loopa do...while loop
11.While true testWhile true test
12.Simplest do whileSimplest do while
13.Simplest while