Program to Find NCR
of a given number
Program
#include
<stdio.h>
void main()
{
int n, r;
float NCR(int,int);
int Factorial(int n);
printf("\nEnter
value for n and r : ");
scanf("%d%d",
&n, &r);
printf("\nThe
NCR = %0.2f", NCR(n, r));
}
float NCR(int n, int
r)
{
int factorial(int);
return((float)factorial(n)
/ ((float)factorial(n - r) * (float)factorial(r)));
}
int factorial(int n)
{
int k, fact;
for(k = 1, fact = 1;
k <= n; k++)
fact = fact * k;
return(fact);
}
No comments:
Post a Comment