Triangle()
is activated with a parameter of 3.
The statement:
return N + Triangle( N-1 );
must have a value for Triangle(N-1) before the addition can be done.
So the first activation of Triangle() causes a
second activation of Triangle(), this time with
a parameter of 3.
See the picture.
Each circle represents an activation. The first activation (with 4) is waiting for the new activation (with 3) to return a result.
Look at the code again. Think about the latest activation.
What does the activation Triangle(3) do?
public int Triangle( int N )
{
if ( N == 1 )
return 1;
else
return N + Triangle( N-1 );
}