kokokozhina

task9_15_9

Dec 2nd, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream> //counting the binomial coefficientes
  2. //check this shit one more time
  3. using namespace std;
  4.  
  5. double binomial(int k, int n)
  6. {  
  7.     double coefficient;
  8.     if (k == 0)
  9.         return 1;
  10.     else
  11.         coefficient = double(n + 1 - k) / k * binomial(k - 1, n);
  12.     return coefficient;
  13. }
  14.  
  15. int main()
  16. {  
  17.     int n, k;
  18.     cout << "Enter the value of k (upper coefficient): ";
  19.     cin >> k;
  20.     cout << "Enter the value of n (lower coefficient): ";
  21.     cin >> n;
  22.  
  23.     cout << "Your binomial coefficient is " << binomial(k, n) << endl;
  24.     system("pause");
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment