Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*
- * 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.
- */
- class FormattingNumbers
- {
- static void Main()
- {
- int a= -1;
- while (a < 0 || a > 500) // Check the entered number. The code can be made without this part.
- {
- Console.Write("Enter an intteger number:\n a = ");
- a = int.Parse(Console.ReadLine());
- if (a < 0 || a > 500)
- {
- Console.WriteLine("The number must be in a range (0;500)");
- }
- }
- Console.Write("Enter some float numbers:\n b = ");
- float b = float.Parse(Console.ReadLine());
- Console.Write(" c = ");
- float c = float.Parse(Console.ReadLine());
- //Prints the table
- Console.WriteLine("|{0,-10:X}|{1,10}|{2,10:F2}|{3,-10:0.000}|",a,Convert.ToString(a,2).PadLeft(10,'0'), b, c);
- //Console.WriteLine("\n|{0,-10}|{1,10}|{2,10:0.##}|{3,-10:0.###}|", a.ToString("X"), Convert.ToString(a, 2).PadLeft(10, '0'), b, c);
- Console.Read();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement