Advertisement
Spocoman

Combinations

Sep 17th, 2023 (edited)
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.  
  9.     int combinations = 0;
  10.  
  11.     for (int a = 0; a <= n; a++) {
  12.         for (int b = 0; b <= n; b++) {
  13.             for (int c = 0; c <= n; c++) {
  14.                 if (a + b + c == n) {
  15.                     combinations++;
  16.                 }
  17.             }
  18.         }
  19.     }
  20.  
  21.     cout << combinations << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement