title: How do I print the following pattern using 3 for loops instead of 4?
body: <p>I'm trying to print the following pattern:</p>
  
  <pre><code>*
  **
  ***
  ****
  *****
  ****
  ***
  **
  *
  </code></pre>
  
  <p>Now, I know how to do it using 4 for loops:</p>
  
  <pre><code>for(i=1;i&lt;=n;i++)
  {
      for(j=1;j&lt;=i;j++)
      {
          cout&lt;&lt;"*";
      }
      cout&lt;&lt;"\n";
  }
  </code></pre>
  
  <p>to print the first half and to print the second half:</p>
  
  <pre><code>for(i=1;i&lt;=n;i++)
   {
      for(j=n;j&gt;i;j--)
      {
          cout&lt;&lt;"*";
      }
       cout&lt;&lt;"\n";
  }
  </code></pre>
  
  <p>Looking closely, both the outer for loops are the same. i.e., 
  for(i=1;i&lt;=n;i++).
  Is there anyway to nest both the 'j' for-loops inside the i-for loop?</p>