• 05-29-2011
Needle_Scratch
Code:

```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 loop
• 05-29-2011
CommonTater
Oh come one... you can figure that out for yourself... can't you?
• 05-29-2011
kmdv
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; }```
• 05-29-2011
Needle_Scratch
I figured that and I get theis :

Code:

``` int fac(int i) {   int ret = 1;   for(;i>1;--i)     ret *= i;   return ret; }```
• 05-29-2011
Needle_Scratch
Quote:

Originally Posted by kmdv
For asking a "quick help" you can only get a quick ignore.

Whata re 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; }```

Thanx, you are very cool
I'm only a beginner
• 05-29-2011
kmdv
It's correct and I guess it wasn't that hard. Next time you should post your results along with the assignment.
• 05-29-2011
Needle_Scratch
my code is correct? or what
• 05-29-2011
phantomotap
Quote:

Next time you should post your results along with the assignment.
Out of curiosity, if that is the way you feel, why did you do it for him this time?

Soma
• 05-29-2011
Needle_Scratch

is it true ?
• 05-29-2011
phantomotap
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
• 05-30-2011
kmdv
Quote:

Originally Posted by phantomotap
Out of curiosity, if that is the way you feel, why did you do it for him this time?

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.

Quote:

Originally Posted by Needle_Scratch
is it true ?

Yes, both are "true", I wouldn't post false code.