Advertisement
Niicksana

Operations Btw Numbers

Dec 8th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 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.             // Exam - 24 April 2016
  14.             int num1 = int.Parse(Console.ReadLine());
  15.             int num2 = int.Parse(Console.ReadLine());
  16.             string oper = Console.ReadLine();
  17.             string evenOdd;
  18.  
  19.             double result;
  20.  
  21.             if (oper == "+" || oper == "-" || oper == "*")
  22.             {
  23.  
  24.                 if (oper == "+")
  25.                 {
  26.                     result = num1 + num2;
  27.                 }
  28.  
  29.                 else if (oper == "-")
  30.                 {
  31.                     result = num1 - num2;
  32.                 }
  33.  
  34.                 else
  35.                 {
  36.                     result = num1 * num2;
  37.  
  38.                 }
  39.  
  40.                 if (result % 2 == 0)
  41.                 {
  42.                     evenOdd = "even";
  43.                 }
  44.  
  45.                 else
  46.                 {
  47.                     evenOdd = "odd";
  48.                 }
  49.  
  50.                 Console.WriteLine("{0} {1} {2} = {3} - {4}", num1, oper, num2, result, evenOdd);
  51.             }
  52.  
  53.  
  54.             else if (oper == "/" || oper == "%")
  55.             {
  56.                 if (num2 == 0)
  57.                 {
  58.                     Console.WriteLine("Cannot divide {0} by zero", num1);
  59.                 }
  60.  
  61.                 else
  62.                 {
  63.                     if (oper == "/")
  64.                     {
  65.                         result = (num1 * 1.0) / (num2 * 1.0);
  66.                         Console.WriteLine("{0} / {1} = {2:f2}", num1, num2, result);
  67.                     }
  68.  
  69.  
  70.                     else
  71.                     {
  72.                         result = num1 % num2;
  73.                         Console.WriteLine("{0} {1} {2} = {3:0}", num1, oper, num2, result);
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement