pupesko

SoftUni - 4.5 Formatting Numbers

Sep 30th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. class FormatingNumbers
  4. {
  5.     static void Main()
  6.     {
  7.     //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.
  8.  
  9.         Console.Write("a= ");
  10.         int a = int.Parse(Console.ReadLine());
  11.  
  12.         while (a < 0 || a > 500)
  13.         {
  14.             Console.WriteLine("a needs to be in the interval from 0 to 500!");
  15.             Console.Write("a= ");
  16.             a = int.Parse(Console.ReadLine());            
  17.         }
  18.        
  19.         Console.Write("b= ");
  20.         float b = float.Parse(Console.ReadLine());
  21.  
  22.         Console.Write("c= ");
  23.         float c = float.Parse(Console.ReadLine());
  24.  
  25.         string inBin = Convert.ToString(a, 2);
  26.         int a1 = int.Parse(inBin);
  27.  
  28.         Console.WriteLine("|{0, -10:X}|{1:0000000000}|{2, 10:F2}|{3, -10:F3}|", a, a1, b, c);
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment