MiroslavKisov

Operations_Between_Numbers

Jul 25th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 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_Between_Numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int N1 = int.Parse(Console.ReadLine());
  14.             int N2 = int.Parse(Console.ReadLine());
  15.             char action = char.Parse(Console.ReadLine());
  16.             string type = string.Empty;
  17.             if((N1==0||N2==0)&&(action=='/'||action=='%'))
  18.             {
  19.                 Console.WriteLine($"Cannot divide {N1} by zero");
  20.             }
  21.             else
  22.             {
  23.                 if (action == '+')
  24.                 {
  25.                     int result = N1 + N2;
  26.                     if(result%2==0)
  27.                     {
  28.                         type = "even";
  29.                     }
  30.                     else
  31.                     {
  32.                         type = "odd";
  33.                     }
  34.                     Console.WriteLine($"{N1} + {N2} = {result} - {type}");
  35.                 }
  36.                 else if(action=='-')
  37.                 {
  38.                     int result = N1 - N2;
  39.                     if (result % 2 == 0)
  40.                     {
  41.                         type = "even";
  42.                     }
  43.                     else
  44.                     {
  45.                         type = "odd";
  46.                     }
  47.                     Console.WriteLine($"{N1} - {N2} = {result} - {type}");
  48.                 }
  49.                 else if (action == '*')
  50.                 {
  51.                     int result = N1 * N2;
  52.                     if (result % 2 == 0)
  53.                     {
  54.                         type = "even";
  55.                     }
  56.                     else
  57.                     {
  58.                         type = "odd";
  59.                     }
  60.                     Console.WriteLine($"{N1} * {N2} = {result} - {type}");
  61.                 }
  62.                 else if (action == '/')
  63.                 {
  64.                     double num1 = N1;
  65.                     double num2 = N2;
  66.                     double result = num1 / num2;
  67.                     Console.WriteLine($"{num1} / {num2} = {result:f2}");
  68.                 }
  69.                 else if(action=='%')
  70.                 {
  71.                     int result = N1 % N2;
  72.                     Console.WriteLine($"{N1} % {N2} = {result}");
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment