Write a C program to find ncr using recursion

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
 int n,r,ncr;
 clrscr();
 printf("\n enter n and r:");
 scanf("%d%d",&n,&r);
 ncr=fact(n)/(fact(n-r)*fact(r));
 printf("\n Binomial co-efficient : %d",ncr);
 getch();
 }
  int fact(int x)
  {
   if(x==0)
   return 1;
   else
   return(x*fact(x-1));
  }

No comments:

Post a Comment