fbinnzhivko

03.00 Операции между числа

Apr 25th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         decimal first = decimal.Parse(Console.ReadLine());
  7.         decimal second = decimal.Parse(Console.ReadLine());
  8.  
  9.         string input = Console.ReadLine();
  10.        
  11.         if (input == "+") /*  case 1 - Събиране(+) */
  12.         {
  13.             if ((first + second) % 2 == 0)
  14.             {
  15.                 Console.WriteLine("{0:f0} + {1:f0} = {2:f0} - even", first, second, first + second);
  16.             }
  17.             else
  18.             {
  19.                 Console.WriteLine("{0:f0} + {1:f0} = {2:f0} - odd", first, second, first + second);
  20.             }
  21.         }
  22.         else if (input == "-") /*  case 2 - Изваждане(-) */  
  23.         {
  24.             if ((first - second) % 2 == 0)
  25.             {
  26.                 Console.WriteLine("{0:f0} + {1:f0} = {2:f0} - even", first, second, first - second);
  27.             }
  28.             else
  29.             {
  30.                 Console.WriteLine("{0:f0} - {1:f0} = {2:f0} - odd", first, second, first - second);
  31.             }
  32.         }
  33.         else if (input == "/") /*  case 3 -  Деление(/) */
  34.         {
  35.  
  36.             if (second != 0)
  37.             {
  38.                 Console.WriteLine("{0:f0} / {1:f0} = {2:f2}", first, second, first / second);
  39.             }
  40.             else if (second == 0)
  41.             {
  42.                 Console.WriteLine("Cannot divide {0} by zero", first);
  43.             }
  44.         }
  45.         else if (input == "*")  /*  case 4 - Умножение(*) */
  46.         {
  47.             if ((first * second) % 2 == 0)
  48.             {
  49.                 Console.WriteLine("{0:f0} * {1:f0} = {2:f0} - even", first, second, first * second);
  50.             }
  51.             else
  52.             {
  53.                 Console.WriteLine("{0:f0} * {1:f0} = {2:f0} - odd", first, second, first * second);
  54.             }
  55.         }
  56.         else if (input == "%") /*  case 5 - Модулно деление(%) */
  57.         {
  58.             if (second != 0)
  59.             {
  60.                 Console.WriteLine("{0:f0} % {1:f0} = {2:f0}", first, second, first % second);
  61.             }
  62.             else if (second == 0)
  63.             {
  64.                 Console.WriteLine("Cannot divide {0} by zero", first);
  65.             }
  66.         }
  67.     }
  68. }
Add Comment
Please, Sign In to add comment