dzungchaos

C++ "TÌm tổ hợp"

Nov 6th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int combination(int k, int n){
  5.     if ( k == 0 || k == n) return 1;
  6.     else return combination(k, n - 1) + combination(k - 1, n - 1);
  7. }
  8.  
  9. int main(){
  10.     int k,n;
  11.     cout << "Nhap k, n = ";
  12.     cin >> k; cin >> n;
  13.     cout << "Ket qua: " << combination( k, n);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment