During my College life as a computer science, I have encountered Factorial problems often at programming. I just want to share this, hope it help.
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
For example:
5! = 1 x 2 x 3 x 4 x 5 = 120
In Programming:
Note: 0! = 1
N = input;
ANS=1;
For ( ctr = N; ctr >=1; ctr--)
{
ANS = ANS * ctr;
}
PRINT(“Total: ” + ANS);
Tuesday, April 22, 2008
Subscribe to:
Posts (Atom)