Advertisement
TodorovP

Operations with Numbers

Jan 27th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 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 Operations_with_Numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var n1 = int.Parse(Console.ReadLine()); // 0...40 000
  14.             var n2 = int.Parse(Console.ReadLine()); // 0...40 000
  15.             var operatoor = Console.ReadLine(); // + , -, *, /, %
  16.  
  17.             double result = 0;
  18.             string parity = "odd";
  19.                                    
  20.             if ((operatoor == "+") || (operatoor == "-") || (operatoor == "*"))
  21.             {
  22.                 if (operatoor == "+")
  23.                 {
  24.                     result = n1 + n2;
  25.                     if ((result % 2 == 0)) parity = "even";
  26.                 }
  27.                 if (operatoor == "-")
  28.                 {
  29.                     result = n1 - n2;
  30.                     if ((result % 2 == 0)) parity = "even";
  31.                 }
  32.                 if (operatoor == "*")
  33.                 {
  34.                     result = n1 * n2;
  35.                     if ((result % 2 == 0)) parity = "even";
  36.                 }
  37.                 Console.WriteLine($"{n1} {operatoor} {n2} = {result} – {parity}");
  38.             }
  39.  
  40.             if (n2 == 0)
  41.             {
  42.                 Console.WriteLine($"Cannot divide {n1} by zero");
  43.                 Environment.Exit(0);
  44.             }
  45.             if (operatoor == "/")
  46.             {
  47.                 result = 1.0 * n1 / n2;
  48.                 Console.WriteLine($"{n1} / {n2} = {result:f2}");
  49.             }
  50.             if (operatoor == "%")
  51.             {
  52.                 result = n1 % n2;
  53.                 Console.WriteLine($"{n1} % {n2} = {result}");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement