Tuesday, October 4, 2011

Program to find the value of nCr





Write a program to find nCr....



Program:

#include<stdio.h>
#include<conio.h>
long int factorial(int n);
void main()
{
int n,r;
long int ncr;
clrscr();
l1:printf("Enter value of n and r to find the value of ncr(n>r)");
scanf("%d%d",&n,&r);
if(n<r)
{
printf("Enter the value of n>r \n.\n.\n.\n.\n.\n.\n.\n.\n.\n.");
goto l1;
}
ncr=factorial(n)/(factorial(r)*factorial(n-r));
printf("Value of nCr : %ld",ncr);
getch();
}

long int factorial(int n)
{
return n>1?n*factorial(n-1):1;
}



Output:




0 comments:

Post a Comment

About Me