Advertisement
lkraichev

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

Oct 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int num1, num2;
  10.     char mat;
  11.  
  12.     cin >> num1 >> num2 >> mat;
  13.  
  14.     if (num1 != 0 && num2 != 0)
  15.     {
  16.         if (mat == '+')
  17.         {
  18.             int num = num1 + num2;
  19.             if (num % 2 == 0)
  20.             {
  21.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - even" << endl;
  22.             }
  23.             else
  24.             {
  25.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  26.             }
  27.         }
  28.         else if (mat == '-')
  29.         {
  30.             int num = num1 - num2;
  31.             if (num % 2 == 0)
  32.             {
  33.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - even" << endl;
  34.             }
  35.             else
  36.             {
  37.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  38.             }
  39.         }
  40.         else if (mat == '*')
  41.         {
  42.             int num = num1 * num2;
  43.             if (num % 2 == 0)
  44.             {
  45.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - even" << endl;
  46.             }
  47.             else
  48.             {
  49.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  50.             }
  51.         }
  52.         else if (mat == '/')
  53.         {
  54.             double num = num1 / num2;
  55.             cout << num1 << ' ' << mat << ' ' << num2 << " = " << fixed << setprecision(2) << num << endl;
  56.         }
  57.         else if (mat == '%')
  58.         {
  59.             double num = num1 % num2;
  60.             cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << endl;
  61.         }
  62.     }
  63.     else
  64.     {
  65.         if (mat == '+')
  66.         {
  67.             int num = num1 + num2;
  68.             if (num % 2 == 0)
  69.             {
  70.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " <<  num << " - even" << endl;
  71.             }
  72.             else
  73.             {
  74.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  75.             }
  76.         }
  77.         else if (mat == '-')
  78.         {
  79.             int num = num1 - num2;
  80.             if (num % 2 == 0)
  81.             {
  82.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - even" << endl;
  83.             }
  84.             else
  85.             {
  86.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  87.             }
  88.         }
  89.         else if (mat == '*')
  90.         {
  91.             int num = num1 * num2;
  92.             if (num % 2 == 0)
  93.             {
  94.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - even" << endl;
  95.             }
  96.             else
  97.             {
  98.                 cout << num1 << ' ' << mat << ' ' << num2 << " = " << num << " - odd" << endl;
  99.             }
  100.         }
  101.         else if (mat == '/')
  102.         {
  103.            
  104.             cout << "Cannot divide " << num1 << " by zero" << endl;
  105.         }
  106.         else if (mat == '%')
  107.         {
  108.            
  109.             cout << "Cannot divide " << num1 << " by zero" << endl;
  110.         }
  111.     }
  112.  
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement