Calculate Gamma function Value
#include <iostream>
using namespace Std;
Class Gamma
{
Private
int i, n;
Double F, prod, result, x, y;
Double a[25];
Public
Double Gamma_fn (double);
void solution ();
};
void Main ()
{
Gamma gamma0;
Gamma0.solution ();
}
void Gamma::solution ()
{
cout << "\ n enter x (x > 0) =";
CIN >> X;
y = x;
if (x > 2)
{
Prod = 1.0;
Todo
{
x--;
Prod *= x;
}while (x > 2);
result = Prod * GAMMA_FN (x);
}
Else
{
result = GAMMA_FN (x);
}
cout << "\ n Gamma function value at << y << point =" << result << Endl;
}
Double gamma::gamma_fn (double y)
{
n = 24;
A[0] = 1.0;
A[1] = 0.5772156649015329;
A[2] =-0.6558780715202538;
A[3] =-0.0420026350340952;
A[4] = 0.1665386113822915;
A[5] =-0.0421977345555443;
A[6] =-0.009621971527877;
A[7] = 0.007218943246663;
A[8] =-0.0011651675918591;
A[9] =-0.0002152416741149;
A[10] = 0.0001280502823882;
A[11] =-0.0000201348547807;
A[12] =-0.0000012504934821;
A[13] = 0.000001133027232;
A[14] =-0.0000002056338417;
A[15] = 0.000000006116095;
A[16] = 0.0000000050020075;
A[17] =-0.0000000011812746;
A[18] = 0.0000000001043427;
A[19] = 0.0000000000077823;
A[20] =-0.0000000000036968;
A[21] = 0.00000000000051;
A[22] =-0.0000000000000206;
A[23] =-0.0000000000000054;
A[24] = 0.0000000000000014;
F = A[n];
for (i = (n-1); I >= 0; i--)
{
f = f * y + a[i];
}
F *= y;
return (1/f);
}