This program calculates the permutation:
using namespace System;
long Factorial(long number)
{
if( number <= 1 )
return 1;
else
return number * Factorial(number - 1);
}
long Permutation(long n, long r)
{
if( r == 0 )
return 0;
if( n == 0 )
return 0;
if( (r >= 0) && (r <= n) )
return Factorial(n) / Factorial(n - r);
else
return 0;
}
int main()
{
Console::WriteLine(L"F(10) = {0}\n",
Factorial(10));
Console::WriteLine(L"F(6) = {0}\n",
Factorial(6));
Console::WriteLine(L"P(10, 4) = {0}\n",
Permutation(10, 4));
return 0;
}
This would produce:
F(10) = 3628800
F(6) = 720
P(10, 4) = 5040
Press any key to continue . . .
|
|