Advertisement
IvanITD

06.OperationsBetweenNumbers

Jan 18th, 2024
837
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | Source Code | 0 0
  1. int N1 = int.Parse(Console.ReadLine());
  2. int N2 = int.Parse(Console.ReadLine());
  3. char symbol = char.Parse(Console.ReadLine());
  4.  
  5. double result = 0.00;
  6.  
  7. if (symbol == '+')
  8. {
  9.     result = N1 + N2;
  10.     if (result % 2 == 0)
  11.     {
  12.         Console.WriteLine($"{N1} + {N2} = {result} - even");
  13.     }
  14.     else
  15.     {
  16.         Console.WriteLine($"{N1} + {N2} = {result} - odd");
  17.     }
  18. }
  19. else if (symbol == '-')
  20. {
  21.     result = N1 - N2;
  22.     if (result % 2 == 0)
  23.     {
  24.         Console.WriteLine($"{N1} - {N2} = {result} - even");
  25.     }
  26.     else
  27.     {
  28.         Console.WriteLine($"{N1} - {N2} = {result} - odd");
  29.     }
  30. }
  31. else if (symbol == '*')
  32. {
  33.     result = N1 * N2;
  34.     if (result % 2 == 0)
  35.     {
  36.         Console.WriteLine($"{N1} * {N2} = {result} - even");
  37.     }
  38.     else
  39.     {
  40.         Console.WriteLine($"{N1} * {N2} = {result} - odd");
  41.     }
  42. }
  43. else if (symbol == '/')
  44. {
  45.     if (N1 == 0 || N2 == 0)
  46.     {
  47.         Console.WriteLine($"Cannot divide {N1} by zero");
  48.     }
  49.     else
  50.     {
  51.         result = (double)N1 / N2;
  52.         Console.WriteLine($"{N1} / {N2} = {result:F2}");
  53.     }
  54. }
  55. else if (symbol == '%')
  56. {
  57.     if (N1 == 0 || N2 == 0)
  58.     {
  59.         Console.WriteLine($"Cannot divide {N1} by zero");
  60.     }
  61.     else
  62.     {
  63.         result = N1 % N2;
  64.         Console.WriteLine($"{N1} % {N2} = {result}");
  65.     }
  66. }
  67.  
Tags: C#
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement