Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
programmingfaster
#include<stdio.h>
#include<conio.h>
long factorial(int);
int main()
{
int number,ncr,npr;
int r;
long fact = 1;
factorial(number);
printf("Enter a number(n) to calculate it's factorial and r such n>r\n");
scanf("%d %d",&number,&r);
printf("%d! = %ld\n", number, factorial(number));
npr=factorial(number)/factorial(number-r);
ncr=factorial(number)/(r*factorial(number-r));
printf("ncr=%d\n",ncr);
printf("npr=%d",npr);
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.