desislava_topuzakova

03. Combinations

Feb 14th, 2022
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.  
  9.     //x1, x2, x3 -> 0 до n
  10.     int count = 0; //брой на валидни комбинации
  11.  
  12.     for (int x1 = 0; x1 <= n ; x1++)
  13.     {
  14.         for (int x2 = 0; x2 <= n ; x2++)
  15.         {
  16.             for (int x3 = 0; x3 <= n; x3++)
  17.             {
  18.                 int sum = x1 + x2 + x3;
  19.                 if (sum == n) {
  20.                     count++;
  21.                 }
  22.             }
  23.         }
  24.     }
  25.  
  26.     cout << count << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment