Advertisement
VyaraG

FormattingNumbers

Nov 28th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. //Write a program that reads 3 numbers: an integer a (0 ≤ a ≤ 500), a floating-point b and a floating-point c and prints them in 4 virtual columns on the console. Each column should have a width of 10 characters. The number a should be printed in hexadecimal, left aligned; then the number a should be printed in binary form, padded with zeroes, then the number b should be printed with 2 digits after the decimal point, right aligned; the number c should be printed with 3 digits after the decimal point, left aligned.
  2.  
  3. class FormattingNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter an integer between 0 and 500: ");
  8.         int a = int.Parse(Console.ReadLine());
  9.  
  10.         Console.Write("Enter a floating-point number: ");
  11.         double b = double.Parse(Console.ReadLine());
  12.  
  13.         Console.Write("Enter a floating-point number: ");
  14.         double c = double.Parse(Console.ReadLine());
  15.  
  16.         Console.WriteLine("|{0,-10}|{1,10}|{2,10:F2}|{3,-10:F3}|", a.ToString("X"), Convert.ToString(a,2).PadLeft(10,'0'), b, c);
  17.     }
  18.    
  19.    
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement