using System; class ShowBinary { /// /// The ShowBinary Program Bishop & Horspool 2002 /// ====================== /// Displays a number in binary notation. /// Illustrates the use of while loops. /// void PrintBinary(int k) { if (k == 0) { Console.WriteLine("0"); return; } string s = ""; while (k > 0) { if (k%2==0) s = '0' + s; else s = '1' + s; k /= 2; } Console.WriteLine(s); } void Go() { Console.WriteLine("Note: enter -1 to exit the program."); for ( ; ; ) { Console.Write("Enter number to display in binary: "); int num = int.Parse(Console.ReadLine()); if (num < 0) return; PrintBinary(num); } } static void Main() { new ShowBinary().Go(); } }