Advertisement
ivoCod

C# SoftUni задача 03.Операции между числа

Apr 3rd, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 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 _2016._04April._24_03.Операции_между_числа
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Console.Write("Въведи цяло число (от 0 до 40000) Num1: ");
  14.             int num1 = int.Parse(Console.ReadLine());
  15.             //Console.Write("Въведи второ цяло число(от 0 до 40000) Num2: ");
  16.             int num2 = int.Parse(Console.ReadLine());
  17.             //Console.Write("Въведи символ за математическа операция (+, -, *, /, %): ");
  18.             string mathOperation = Console.ReadLine();
  19.  
  20.             //if ((num1 < 0 || num1 > 40000) || (num2 < 0 || num2 > 40000))
  21.            // {
  22.              //   Console.WriteLine("Invalid number");
  23.            // }
  24.            // else
  25.             //{
  26.                 var sum = (num1 + num2);
  27.                 var subtraction = (num1 - num2);
  28.                 var multiply = (num1 * num2);
  29.                 var overage = num1 % ((double)num2);
  30.  
  31.  
  32.                 if (mathOperation == "+")
  33.                 {
  34.                     if (sum % 2 == 0)
  35.                     {
  36.                         Console.WriteLine($"{num1} + {num2} = {sum} - even");
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine($"{num1} + {num2} = {sum} - odd");
  41.                     }
  42.                 }
  43.  
  44.                 if (mathOperation == "-")
  45.                 {
  46.                     if (subtraction % 2 == 0)
  47.                     {
  48.                         Console.WriteLine($"{num1} - {num2} = {subtraction} - even");
  49.                     }
  50.                     else
  51.                     {
  52.                         Console.WriteLine($"{num1} - {num2} = {subtraction} - odd");
  53.                     }
  54.                  }
  55.  
  56.  
  57.                  if (mathOperation == "*")
  58.                  {
  59.                     if (multiply % 2 == 0)
  60.                     {
  61.                         Console.WriteLine($"{num1} * {num2} = {multiply} - even");
  62.                     }
  63.                     else
  64.                     {
  65.                         Console.WriteLine($"{num1} * {num2} = {multiply} - odd");
  66.                     }
  67.                  }
  68.  
  69.  
  70.                 if (mathOperation == "%" || mathOperation == "/")
  71.                 {
  72.                     if (num2 == 0)
  73.                     {
  74.                         Console.WriteLine($"Cannot divide {num1} by zero");
  75.                     }
  76.                     else if (mathOperation == "%")
  77.                     {
  78.                         Console.WriteLine($"{num1} % {num2} = {overage}");
  79.                     }
  80.                     else if (mathOperation == "/")
  81.                     {
  82.                         var div = num1 / ((double)num2);
  83.                         Console.WriteLine($"{num1} / {num2} = {div:f2}");
  84.                     }
  85.  
  86.                    
  87.                 }
  88.  
  89.  
  90.  
  91.             //}
  92.         }
  93.     }
  94. }
  95. За да мине на 100% Judge системата на SoftUni съм поставил в коментар нещата, които не се изискват по условие. Кода работи и с тях, системата не ги отчита като верни резултати.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement