Advertisement
braveheart1989

DifferentIntegersSize

May 19th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _17.DifferentIntegersSize
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string a = Console.ReadLine();
  15.            
  16.             try
  17.             {
  18.                 long n = long.Parse(a);
  19.                 //BigInteger n = BigInteger.Parse(Console.ReadLine());
  20.                 //string n = Console.ReadLine();
  21.                // long n = long.Parse(Console.ReadLine());
  22.                 List<string> storeNumber = new List<string>();
  23.                 string sbytes = "sbyte";
  24.                 string bytes = "byte";
  25.                 string shorts = "short";
  26.                 string ushorts = "ushort";
  27.                 string ints = "int";
  28.                 string uints = "uint";
  29.                 string longs = "long";
  30.  
  31.                 if (n >= sbyte.MinValue && n <= sbyte.MaxValue)
  32.                 {
  33.                     storeNumber.Add(sbytes);
  34.                 }
  35.                 if (n >= byte.MinValue && n <= byte.MaxValue)
  36.                 {
  37.                     storeNumber.Add(bytes);
  38.                 }
  39.                 if (n >= short.MinValue && n <= short.MaxValue)
  40.                 {
  41.                     storeNumber.Add(shorts);
  42.                 }
  43.                 if (n >= ushort.MinValue && n <= ushort.MaxValue)
  44.                 {
  45.                     storeNumber.Add(ushorts);
  46.                 }
  47.                 if (n >= int.MinValue && n <= int.MaxValue)
  48.                 {
  49.                     storeNumber.Add(ints);
  50.                 }
  51.                 if (n >= uint.MinValue && n <= uint.MaxValue)
  52.                 {
  53.                     storeNumber.Add(uints);
  54.                 }
  55.                 if (n >= long.MinValue && n <= long.MaxValue)
  56.                 {
  57.                     storeNumber.Add(longs);
  58.                 }
  59.                 Console.WriteLine("{0} can fit in:", n);
  60.                 for (int i = 0; i < storeNumber.Count; i++)
  61.                 {
  62.                     Console.WriteLine("* {0}", storeNumber[i]);
  63.                 }
  64.             }
  65.             catch (OverflowException)
  66.             {
  67.                    
  68.                 //BigInteger n = BigInteger.Parse(Console.ReadLine());
  69.                 //string n = Console.ReadLine();
  70.                 Console.WriteLine("{0} can't fit in any type",a);
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement