title: how to understand which recursive function program needs
body: <p>I am testing some codes related to recursion function. I saw the recursion method for towers of hanoi problem but I am very confused, two recursive functions are using in if condition. The understanding of the program till now is first it set n to zero and after this I dont know how it increases the n and how it knows which recursive function it should call first. I am weak in understanding of recursive function,please help me in understanding the working of recursive function of given program.</p>
  
  <p>// Recursive Towers of Hanoi</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void towersOfHanoi(int n, int x, int y, int z)
  {// Move the top n disks from tower x to tower y.
   // Use tower z for intermediate storage.
      if (n &gt; 0) // Base Case
      {
          towersOfHanoi(n - 1, x, z, y);
          cout &lt;&lt; "Move top disk from tower " &lt;&lt; x &lt;&lt; " to top of tower " &lt;&lt; y &lt;&lt; endl;
          towersOfHanoi(n - 1, z, y, x);
  
      }
  
  } // Recursive Procedure
  
  void main(void)
  {
      cout &lt;&lt; "Moves for a three disk problem are" &lt;&lt; endl;
      towersOfHanoi(3, 1, 2, 3);
      system("pause");
  }
  </code></pre>