Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. using System;
  2. namespace _10.DataOverflow
  3. {
  4. class Program
  5. {
  6. public static void Main()
  7. {
  8. var firstNum = decimal.Parse(Console.ReadLine());
  9. var secondNum = decimal.Parse(Console.ReadLine());
  10. //lowest
  11. var biggerNum = Math.Max(firstNum, secondNum);
  12. var smallerNum = Math.Min(firstNum, secondNum);
  13. var biggerType = string.Empty;
  14. var smallerType = string.Empty;
  15. //byteBigger
  16. if (byte.MinValue <= biggerNum && biggerNum <= byte.MaxValue)
  17. {
  18. biggerType = "byte";
  19. }
  20. //ushortBigger
  21. else if (ushort.MinValue <= biggerNum && biggerNum <= ushort.MaxValue)
  22. {
  23. biggerType = "ushort";
  24. }
  25. else if (uint.MinValue <= biggerNum && biggerNum <= uint.MaxValue)
  26. {
  27. biggerType = "uint";
  28. }
  29. else if (ulong.MinValue <= biggerNum && biggerNum <= ulong.MaxValue)
  30. {
  31. biggerType = "ulong";
  32. }
  33. //small
  34. if (byte.MinValue <= smallerNum && smallerNum <= byte.MaxValue)
  35. {
  36. smallerType = "byte";
  37. }
  38. //ushortBigger
  39. else if (ushort.MinValue <= smallerNum && smallerNum <= ushort.MaxValue)
  40. {
  41. smallerType = "ushort";
  42. }
  43. else if (uint.MinValue <= smallerNum && smallerNum <= uint.MaxValue)
  44. {
  45. smallerType = "uint";
  46. }
  47. else if (ulong.MinValue <= smallerNum && smallerNum <= ulong.MaxValue)
  48. {
  49. smallerType = "ulong";
  50. }
  51. Console.WriteLine("bigger type: {0}", biggerType);
  52. Console.WriteLine("smaller type: {0}", smallerType);
  53. //OverflowCheck
  54. var overflow = biggerNum;
  55. if (smallerType == "byte")
  56. {
  57. overflow = overflow / byte.MaxValue;
  58. Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
  59. }
  60. else if (smallerType == "ushort")
  61. {
  62. overflow = overflow / ushort.MaxValue;
  63. Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
  64. }
  65. else if (smallerType == "uint")
  66. {
  67. overflow = overflow / uint.MaxValue;
  68. Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
  69. }
  70. else if (smallerType == "ulong")
  71. {
  72. overflow = overflow / ulong.MaxValue;
  73. Console.WriteLine("{0} can overflow {1} {2} times", biggerNum, smallerType, Math.Round(overflow));
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement