Advertisement
coasterka

#4FormattingNumbers

Mar 19th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2.  
  3. class FormattingNumbers
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         Console.WriteLine("Please enter an integer number N satisfying the condition 0 <= N <= 500");
  8.         int a = int.Parse(Console.ReadLine());
  9.         while (a < 0 || a > 500)
  10.         {
  11.             Console.WriteLine("Invalid number! Try again.");
  12.             a = int.Parse(Console.ReadLine());
  13.             continue;
  14.         }
  15.         Console.WriteLine("Please enter a floating-point number N");
  16.         float b = float.Parse(Console.ReadLine());
  17.         Console.WriteLine("Please enter a floating-point number N");
  18.         float c = float.Parse(Console.ReadLine());
  19.         Console.Write("|" + Convert.ToString(a, 16).PadRight(10).ToUpper());
  20.         Console.Write("|" + Convert.ToString(a, 2).PadLeft(10, '0'));        
  21.         bool floatCheckB = Convert.ToString(b).IndexOf(".") > 0;
  22.         Console.Write(floatCheckB ? "|{0,10:0.00}" : "|{0,10}", b);
  23.         bool floatCheckC = Convert.ToString(c).IndexOf(".") > 0;
  24.         Console.WriteLine(floatCheckC ? "|{0,-10:0.000}|" : "|{0,-10}|", c);        
  25.         Console.ReadLine();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement