Originally posted by Barry Gaunt:
Here's another way using a for loop
OK, looking at this code.....
Taking the number 3 as an example
What happens??
OK...
The integer 3 enters the method as m.
And then within the for loop below
for ( int n = m ; n > 1 ; n-- )
We FIRSTLY decrease the value of 3 by 1, i.e., so we get 2. And then we multily this by f, i.e., the value 1. - 1 X 2 = 2
Then do the same thing again with the previously decremented value of 2, using the for loop, so we get 1.
And then we multiply this by f, i.e., the value 1. - 1 X 1 = 1
But, 2 x 1 = 2
How do we get 6???