please Switch if statment to for loopCode:int Factorial ( int number ) // Pre: number is assigned and number >= 0. { if ( number == 0) // base case return 1 ; else // general case return (number * Factorial ( number - 1 )); }
please Switch if statment to for loopCode:int Factorial ( int number ) // Pre: number is assigned and number >= 0. { if ( number == 0) // base case return 1 ; else // general case return (number * Factorial ( number - 1 )); }
Oh come one... you can figure that out for yourself... can't you?
For asking a "quick help" you can get a quick ignore.
What are you having problem with? Do you know what this code does?
Code:unsigned int Factorial(unsigned int number) { unsigned int x = 1; for (unsigned int i = 2; i <= number; i++) { x *= i; } return x; }
I figured that and I get theis :
Code:int fac(int i) { int ret = 1; for(;i>1;--i) ret *= i; return ret; }
It's correct and I guess it wasn't that hard. Next time you should post your results along with the assignment.
my code is correct? or what
Out of curiosity, if that is the way you feel, why did you do it for him this time?Next time you should post your results along with the assignment.
Soma
so , what about your code?
is it true ?
O_o
If you know that the recursive version is correct, why don't you just compare the results of both versions up to 12 or 13 or so?
Soma
I did not want to see next thread with a simple question, dragging on forever, instructing the newcomer how he should ask questions the smart way. Anyway, I did not avoid it, cuz it already reaches the 10th reply.
Yes, both are "true", I wouldn't post false code.
Last edited by kmdv; 05-30-2011 at 12:27 AM.