You are on page 1of 1

Draw the flowchart and write a recursive C function to find the factorial of a n

umber, n!, defined by fact(n)=1, if n=0. Otherwise fact(n)=n*fact(n-1). Using th


is function, write a C program to compute the binomial coefficient nCr. Tabulate
the results for different values of n and r with suitable messages.
Program:
#include<stdio.h>
#include<conio.h>
int fact(int n)
{
if(n==0)
{
return 1;
}
return (n*fact(n-1));
}
void main()
{
int n,r,res;
clrscr();
printf("Enter the value of n and r \n");
scanf("%d%d",&n,&r);
res=fact(n)/(fact(n-r)*fact(r));
printf("The nCr is %d",res);
getch();
}
Sample output
Enter the value of n and r 4 2
The nCr is 6

You might also like