0
3.5kviews
What do you mean by Recursion? Write a program which will accept two numbers, n and r and calculate value of $nC_r$ = n! / r! (n - r)!. Program should make use of recursion.
1 Answer
written 7.7 years ago by |
Recursive Function:
Algorithm:
Main () Function:
Exponential (parameters: x, y)
Program:
#include <stdio.h>
#include <conio.h>
int main(){
int n, r, C;
int fact(int k);
printf("Enter the number n and r:");
scanf("%d%d", &n, &r);
C = fact(n)/fact(n-r);
printf("nCr=%d\n", C);
getch();
}
int fact(int k) {
if(k==1)
return 1;
else
return (k*fact(k-1));
}
Output:
Enter the number n and r = 5 3
$nC_r$ = 60
Explanation: