This article illustrates the factorial, permutation and combination of C language implementations. Share to everyone for your reference. Specifically as follows:
#include <stdio.h>
int factorial (int n)
{
int i=0;
int sum=1;
int array[]={0};
for (i=n;i>=1;i--)
{
sum=sum*i;
}
return sum;
}
int arrangement (int n,int m)
{
int result=0;
if (m>n)
{
printf ("Your input is wrong, the number above cannot be larger than below!") OK? ");
return 0;
}
if (m<n)
{
result=factorial (n)/factorial (n-m);
return result;
}
int combination (int n,int m)
{
int result=0;
if (m>n)
{
printf ("Your input is wrong, the number above cannot be larger than below!") OK? ");
return 0;
}
if (m<n)
{
int temp=0;
Temp=factorial (n-m) *factorial (m);
Result=factorial (n)/temp;
return result;
}
Main ()
{
int res=0;
Res=arrangement (5,2);
printf ("%d", res);
System ("pause");
}
I hope this article will help you with the C language program.