Thread: Easy Question
View Single Post
Old 2009-10-01, 20:24   #8
m_f_h's Avatar
Feb 2007

24·33 Posts

Originally Posted by Mini-Geek View Post
Here's an example in Java that uses BigInteger, an arbitrary-precision integer, and prints every factorial up to the size you specify:
Maybe the answer the O.P. was looking for is rather something like
int factorial(int n){ int f=1; while( n>1 ) f *= n--; return(f); }

main(){ int n; for( n=1; n<10; n++ ) printf( "%d ! = %d\n", n, factorial(n)); }
Of course I know that I could have used "unsigned long long" or mpz instead of "int" in factorial, but w.r.t. n1=1; n2=2; ... it should be just perfect as is.
m_f_h is offline   Reply With Quote