For calculating nCr [ i.e. n ! / ( r ! * ( n-r )! ) ], written the below code.
Perl code:
($i,$j)=(1000,100);
print fact($i)/(fact($j)*(fact($i-$j)));
sub fact{
return 1 if $_[0]<=1;
return $_[0]*fact($_[0]-1);
}
which is giving output as "-NaN" but,
same logic code in python gives correct result.
Python code:
def fact(x):
if x <= 1:
return 1
return x*f(x-1)
v,y = 1000,100
print fact(v)/(fact(y)*fact(v-y))
Kindly let me know what changes I have to made in perl code to make it work for bigger numbers.(And also I tried to use "bigint" too, But didnot worked)
Edit:
Thank you all for the response.
Sorry that, I have missed ; and -1.
I think bigint is dependent on machine configuration