Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.OperationsWithNumbers
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var n1 = int.Parse(Console.ReadLine());
  14. var n2 = int.Parse(Console.ReadLine());
  15. string operation = Console.ReadLine();
  16. double sum = 0;
  17.  
  18. if (operation == "+")
  19. {
  20. sum = n1 + n2;
  21. if (sum % 2 == 0)
  22. {
  23. Console.WriteLine("{0} + {1} = {2} - even", n1, n2, sum);
  24. }
  25. else
  26. {
  27. Console.WriteLine("{0} + {1} = {2} - odd", n1, n2, sum);
  28. }
  29.  
  30. }
  31. else if (operation == "-")
  32. {
  33. Console.Write($"{n1} - {n2} = {n1 - n2} - ");
  34. Console.WriteLine((n1 - n2) % 2 == 0 ? "even" : "odd");
  35. }
  36. else if (operation == "*")
  37. {
  38. sum = n1 * n2;
  39. if (sum % 2 == 0)
  40. {
  41. Console.WriteLine("{0} * {1} = {2} - even", n1, n2, sum);
  42. }
  43. else
  44. {
  45. Console.WriteLine("{0} * {1} = {2} - odd", n1, n2, sum);
  46. }
  47. }
  48. else if (operation == "/")
  49. {
  50. if (n2 == 0)
  51. {
  52. Console.WriteLine("Cannot divide {0} by zero", n1);
  53. }
  54. else
  55. {
  56. sum = n1 / n2;
  57. Console.WriteLine("{0} / {1} = {2}", n1, n2, sum);
  58. }
  59. }
  60. else if (operation == "%")
  61. {
  62. if (n2 == 0)
  63. {
  64. Console.WriteLine("Cannot divide {0} by zero", n1);
  65. }
  66. else
  67. {
  68. sum = n1 % n2;
  69. Console.WriteLine("{0} % {1} = {2}", n1, n2, sum);
  70. }
  71.  
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement