/* 10(a). w.a.p. to read 2 integer numbers n & r. write a function to calculate factorial of a number. using the function calculate : (a) n!/(n-r)! (b) n!/((n-r)! * r!) */
#include<stdio.h>
#include<conio.h>
void main()
{
long int n,r,t1,t2,t3; /* Variable Declarations */
long int fact(long int x); /* Function Prototype */
clrscr();
printf("Enter a numbers n & r : ");
scanf("%ld %ld",&n,&r);
if ((n>0) && (r>0) && ((n-r)>0))
{
/* Calling 'fact' function */
t1=fact(n-r);
t2=fact(n);
t3=fact(r);
printf("\nFactorial value of n!/(n-r)! is %ld",(t2/t1));
printf("\nFactorial value of n!/((n-r)! * r!) is %ld",(t2/(t1*t3)));
}
else printf("!!! Invalid Entry. Please try again. !!!");
getch();
}
long int x;
long int fact(x) /* Function Definition 'fact' to find factorial value */
{
long int tot,i;
if (x <= 0)
{
return(1);
}
else
{
tot = 1;
for (i=x; i>=1; i--)
{
tot = tot * i;
}
}
return(tot);
}