Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Седма_задача___операции_между_числа
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double N1 = double.Parse(Console.ReadLine());
  10.             double N2 = double.Parse(Console.ReadLine());
  11.             double result = 0;
  12.             string evenOrOdd = string.Empty;
  13.             string operation = Console.ReadLine();
  14.  
  15.             if (operation == "+" || operation == "-" || operation == "*")
  16.             {
  17.                 if (operation == "+")
  18.                 {
  19.                     result = N1 + N2;
  20.                 }
  21.                 else if (operation == "-")
  22.                 {
  23.                     result = N1 - N2;
  24.                 }
  25.                 else if (operation == "*")
  26.                 {
  27.                     result = N1 * N2;
  28.                 }
  29.                 if (result % 2 == 0)
  30.                 {
  31.                     evenOrOdd = "even";
  32.                 }
  33.                 else if (result % 2 != 0)
  34.                 {
  35.                     evenOrOdd = "odd";
  36.                 }
  37.                 Console.WriteLine($"{N1} {operation} {N2} = {result} - {evenOrOdd}");
  38.             }
  39.             else
  40.             {
  41.                 if (operation == "/" && N2 != 0)
  42.                 {
  43.                     result = N1 / N2;
  44.                     Console.WriteLine($"{N1} / {N2} = {result:f2}");
  45.                 }
  46.                 else if (N2 == 0)
  47.                 {
  48.                     Console.WriteLine($"Cannot divide {N1} by zero");
  49.                 }
  50.                 else if (operation == "%")
  51.                 {
  52.                     result = N1 % N2;
  53.                     Console.WriteLine($"{N1} % {N2} = {result}");
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement