Saravanan Selvamani <saravananselvamani@...> writes:
> Anyone knows how to find the factorial of a number without
> using loops , arithmetic operator,case structure.I guess that this has to be
> done by using bitwise operator.but i dont know how.
Use lookup tables. If you are using 32 bit ints to store numbers, you need a
lookup table till 12.
uint32_t factorial_lut[] = {
1,
1,
2,
6,
24,
120,
720,
5040,
40320,
362880,
3628800,
39916800,
479001600,
};
uint32_t factorial(uint32_t n)
{
if (n < 13)
return factorial_lut[n];
else
return -1;
}
I could think of one reason why you would ever want to do this is - speed.
Regards,
Vijay
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc