DidiMilikina

06.Сбор или Произведение

Oct 22nd, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. //URL FOR THE TASK: https://judge.softuni.bg/Contests/Practice/Index/642#5
  2.  
  3. #include  <iostream>
  4. using namespace  std;
  5.  
  6. int main()
  7. {
  8.    
  9.     int number;
  10.     cin >> number;
  11.  
  12.     int sum = 0;
  13.     int multiplication = 0;
  14.     int counter = 0;
  15.     for (int i = 1; i <= 30; ++i)
  16.     {
  17.         for (int j = 1; j <= 30; ++j)
  18.         {
  19.             for (int k = 1; k <= 30; ++k)
  20.             {
  21.                 sum = i + j + k;
  22.                 if ((i < j && j < k) && sum == number)
  23.                 {
  24.                     cout << i << " + "
  25.                     << j << " + "
  26.                     << k << " = "
  27.                     << number << endl;
  28.                     counter++;
  29.                 }
  30.  
  31.                 multiplication = i * j * k;
  32.                 if ((i > j && j > k) && multiplication == number)
  33.                 {
  34.                     cout << i << " * "
  35.                         << j << " * "
  36.                         << k << " = "
  37.                         << number << endl;
  38.                     counter++;
  39.                 }
  40.             }
  41.         }
  42.     }
  43.     if (!counter)
  44.     {
  45.         cout << "No!" << endl;
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment