- #1
Omid
- 182
- 0
Look at this code :
27: unsigned int factorial(unsigned int a)
28: {
29: if (a == 1)
30: return 1;
31: else
32: {
33: a *= factorial(a-1);
34: return a;
35: }
36: }
The code evaluates fcatorial of "a". The only point I don't get is the return in line 30. When the function is called, each time "a" is increased by 1, so it will reach 1 finally. If so the function must always return 1 and not a. Because always reach 1.
Thanks
27: unsigned int factorial(unsigned int a)
28: {
29: if (a == 1)
30: return 1;
31: else
32: {
33: a *= factorial(a-1);
34: return a;
35: }
36: }
The code evaluates fcatorial of "a". The only point I don't get is the return in line 30. When the function is called, each time "a" is increased by 1, so it will reach 1 finally. If so the function must always return 1 and not a. Because always reach 1.
Thanks