Advertisement
kuruku

FormattingNumbers

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