Factorial in C++
Example for versions
Borland C++ Builder 6,
Microsoft Visual C++ 6,
Microsoft Visual C++ 9 (2008),
g++ 3.4.5
This example uses recursive factorial definition.
#include "stdio.h"
__int64 factorial(__int64 n)
{
return ( n==0 ? 1 : n*factorial(n-1) );
}
int main(int argc, char* argv[])
{
for (int n=0; n<=16; n++)
printf( "%d! = %I64d\n", n, factorial(n) );
return 0;
}
Comments
]]>blog comments powered by Disqus
]]>