Bangeev

Untitled

Nov 22nd, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. $num1 = intval(readline());
  4. $num2 = intval(readline());
  5.         $operation = strval(readline());
  6.  
  7.        $type = "";
  8.  
  9.         switch ($operation) {
  10.             case '+':
  11.                 $sum = $num1 + $num2;
  12.  
  13.                 if ($sum % 2 == 0) {
  14.                     $type = "even";
  15.                 } else {
  16.                     $type = "odd";
  17.                 }
  18.                 printf("%d %s %d = %d - %s", $num1, $operation, $num2, $sum, $type);
  19.                 break;
  20.             case '-':
  21.                 $diff = $num1 - $num2;
  22.                 if ($diff % 2 == 0) {
  23.                     $type = "even";
  24.                 } else {
  25.                     $type = "odd";
  26.                 }
  27.                 printf("%d %s %d = %d - %s", $num1, $operation, $num2, $diff, $type);
  28.                 break;
  29.             case '*':
  30.                  $product = $num1 * $num2;
  31.                 if ($product % 2 == 0) {
  32.                     $type = "even";
  33.                 } else {
  34.                     $type = "odd";
  35.                 }
  36.                 printf("%d %s %d = %d - %s", $num1, $operation, $num2, $product, $type);
  37.                 break;
  38.             case '/':
  39.                 $division = $num1 * 1.0 / $num2;
  40.                 if ($num2 != 0) {
  41.                     printf("%d %s %d = %.2f ", $num1, $operation, $num2, $division);
  42.                 }else{
  43.                     printf("Cannot divide %d by zero", $num1);
  44.                 }
  45.                 break;
  46.             case '%':
  47.  
  48.                 if ($num2 != 0) {
  49.                     $left = $num1 % $num2;
  50.                     printf("%d %s %d = %d ", $num1, $operation, $num2, $left);
  51.                 }else{
  52.                     printf("Cannot divide %d by zero", $num1);
  53.                 }
  54.                 break;
  55.  
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment