Advertisement
Guest User

FormatingExample

a guest
Aug 21st, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FormatingExample
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.Write("Please, enter how many test cases you would like to run: ");
  15.             int tests = int.Parse(Console.ReadLine());
  16.             short[] a = new short[tests];
  17.             double[] b = new double[tests];
  18.             double[] c = new double[tests];
  19.             string[] columnA = new string[tests];
  20.             for (int i = 0; i < tests; i++)
  21.             {
  22.                 System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  23.                 Console.Write("Enter an integer: ");
  24.                 a[i] = short.Parse(Console.ReadLine());
  25.                 Console.Write("Enter first floating - point number: ");
  26.                 b[i] = double.Parse(Console.ReadLine());
  27.                 Console.Write("Enter second floating - point number: ");
  28.                 c[i] = double.Parse(Console.ReadLine());
  29.                 columnA[i] = Convert.ToString(a[i], 2);
  30.             }
  31.             Console.WriteLine("|{0,-10}|{1,10}|{2,10}|{3,-10}|", "Integer a", "Int to bin", "Double 1", "Double 2");
  32.             for (int i = 0; i < tests; i++)
  33.             {
  34.                 if (b[i] > (int) b[i] || c[i] > (int) c[i])
  35.                 {
  36.                     Console.WriteLine("|{0, -10:X}|{1}|{2,10:0.00}|{3,-10:0.000}|", a[i], columnA[i].PadLeft(10, '0'), b[i], c[i]);
  37.                 }
  38.                 else
  39.                 {
  40.                     Console.WriteLine("|{0, -10:X}|{1}|{2,10:0.##}|{3,-10:0.###}|", a[i], columnA[i].PadLeft(10, '0'), b[i], c[i]);
  41.                 }
  42.                
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement