Reputation: 29
I tried out bc but if i try to find the factorial of number 50 it shows me 1 instead of 30414093201713378043612608166064768844377641568960512000000000000
read T
while ((T--)); do
read n
factorial=1
for ((i = 1; i <= $n; i++)); do
factorial=$(( i * factorial ))
done
echo $factorial
done
Upvotes: 1
Views: 711
Reputation: 1021
With bc works fine:
echo "define f (x) {
if (x <= 1) return (1);
return (f(x-1) * x);
}
f(50) " | bc
Upvotes: 3