A function called combthat takes twoparameters: n,rand returns the value of n choose r.Sample command => output:(display (comb 6 3))=> 20Hint: The value of n choose r, C(n,r),is recursively defined as:C(n,r) = n, if r =1= 1, if r = n or r = 0= C(n-1,r-1) + C(n-1, r), otherwise
program language Scheme
import
java.util.*;
class
Combinatorics {
static
int
Solve(
int
n,
int
r)
{
if
(r ==
0
|| r == n)
return
1
;
return
Solve(n -
1
, r -
1
) +
Solve
(n -
1
,
r);
}
public
static
void
main(String[]
args)
{
int
n =
5
, r =
2
;
System.out.println(
Solve(n,
r));
}
}
Get Answers For Free
Most questions answered within 1 hours.