| 1 | // File: fig0625.cpp |
| 2 | // Computer Systems, Fourth Edition |
| 3 | // Figure 6.25 |
| 4 | |
| 5 | #include <iostream> |
| 6 | using namespace std; |
| 7 | |
| 8 | int binCoeff (int n, int k) { |
| 9 | int y1, y2; |
| 10 | if ((k == 0) || (n == k)) { |
| 11 | return 1; |
| 12 | } |
| 13 | else { |
| 14 | y1 = binCoeff (n - 1, k); // ra2 |
| 15 | y2 = binCoeff (n - 1, k - 1); // ra3 |
| 16 | return y1 + y2; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | int main () { |
| 21 | cout << "binCoeff (3, 1) = " << binCoeff (3, 1); // ra1 |
| 22 | cout << endl; |
| 23 | return 0; |
| 24 | } |