Advertisement
aluin

FormatingNumbers

Mar 31st, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2.  
  3. /*05. 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. Examples:
  4. a b c result
  5. 254 11.6 0.5 |FE |0011111110| 11.60|0.500 |
  6. 499 -0.5559 10000 |1F3 |0111110011| -0.56|10000 |
  7. 0 3 -0.1234 |0 |0000000000| 3|-0.123 |
  8. */
  9.  
  10. class FormattingNumbers
  11. {
  12. static void Main()
  13. {
  14. Console.Write("Enter an integer A (0 <= a <= 500) = ");
  15. int numA = int.Parse(Console.ReadLine());
  16. Console.Write("Enter a floating-point B = ");
  17. float numB = float.Parse(Console.ReadLine());
  18. Console.Write("Enter a floating-point C = ");
  19. float numC = float.Parse(Console.ReadLine());
  20.  
  21. string numAHex = numA.ToString("X");
  22. string numAbin = Convert.ToString(numA, 2).PadLeft(10,'0');
  23.  
  24. Console.WriteLine();
  25. Console.WriteLine("|{0,-10}|{1,0}|{2,10}|{3,-10}|", numAHex, numAbin, Math.Round(numB, 2), Math.Round(numC, 3));
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement