factorial
Posted: Mon Jan 09, 2012 7:28 pm
how can i calculate the factorial of a number>20 ?
Code: Select all
#define MAXS something // 'something' is the maximum number of digits you need
struct BigInt
{
int digit[MAXS]; // let N is a big integer, then digit[i] is it's (i+1)'th digit
BigInt ( string S = "" ) \\initializing
{
for ( int i=0;i<S.size();++i)
{
digit[i] = S[i] - '0';
}
for ( int i = S.size();i<MAXS;i++) digit[i] = 0;
}
BigInt ()
{
BigInt("");
}
BigInt add ( BigInt B )
{
int carry = 0;
BigInt C;
for( int i =0; i< MAXS;i++)
{
C.digit[i] = B.digit[i] + digit[i] + carry;
carry = C.digit[i]/10;
C.digit[i] %= 10;
}
return C;
}
BigInt substract ( BigInt B )
{
//code something that substract
}
BigInt multiply ( BigInt B )
{
//code something that multiply
}
//other codes.....
};
Code: Select all
def factorial(m):
if x==1:
return 1
else:
return m*factorial(m-1)
print factorial(m)
Code: Select all
<?php
function fac($int)
{
if($int==1)
return 1;
else
return $int*fac($int-1);
}
$number="500"; /as u wish
echo fac($number);
?>