@Kernelpanic
you need an exit condition, something like this
or if you want big factorial
you could also use BigFloat instead of BigInt
fak(1000000)
8.263931688331240062376646103172666291135347978963873045167775885563379611039583e+5565708
you need an exit condition, something like this
Code: (Select All)
function fak(n::Int)
if n==0
return 1
else
return n*fak(n-1)
end
end
or if you want big factorial
Code: (Select All)
function fak(n::Int)
if n==0
return BigInt(1)
else
return n*fak(n-1)
end
end
you could also use BigFloat instead of BigInt
Code: (Select All)
function fak(n::Int)
f::BigFloat=1
if n==0
return f
else
for i::Int=1:n
f*=i
end
end
return f
end
fak(1000000)
8.263931688331240062376646103172666291135347978963873045167775885563379611039583e+5565708