Advertisement
desislava_topuzakova

03. Combinations

Feb 12th, 2023
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin >> n;
  8.  
  9. int count = 0; //брой на комбинациите, които са валидни
  10.  
  11. //1. комбинация от 3 числа
  12.  
  13. for (int first = 0; first <= n; first++)
  14. {
  15. for (int second = 0; second <= n; second++)
  16. {
  17. for (int third = 0; third <= n; third++)
  18. {
  19. //комбинация от числата: first, second, third
  20. if (first + second + third == n)
  21. {
  22. //валидна комбинация
  23. // cout << first << " + " << second << " + " << third << " = " << n << endl;
  24. count++;
  25. }
  26. }
  27. }
  28. }
  29.  
  30. cout << count;
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement