Senin, 06 Desember 2010

Factorial Function

When I told to compute the factorial function, I think as a human being.

n! = n x (n-1) x (n-2) x (n-3) x ....


But then how we write a program that compute a factorial? Here's the factorial function


int factorial (int n)
{
int product = 1;
while (n>0)
{
product = n * product;
n--;
}
return product;
}

2 komentar:

ikram mengatakan...

Ini postingan apa Zak... hehehe *pusing*

Wibowo Kosasih mengatakan...

Halo Bung Zaki. Salam kenal.
Selamat menunaikan ibadah puasa.