title: How to print the butterfly pattern using C++?
body: <p>So I am taking  a C++ course during which I was asked to write a program to print the following butterfly pattern:</p>
  <pre><code>*      *
  **    **
  ***  ***
  ********
  ********
  ***  ***
  **    **
  *      *
  </code></pre>
  <p>So, this is what I wrote:</p>
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      
      int n;
      cin&gt;&gt;n;
  
      for(int row=1; row&lt;=n; row++){
          for(int j=1; j&lt;=2*n; j++){
              if(j&lt;=row||j&gt;=(2*n)-row){
                  cout&lt;&lt;&quot;*&quot;;
              
              }
              else{
                  cout&lt;&lt;&quot; &quot;;
              }
          }
          cout&lt;&lt;endl;
      }
      for(int row=n; row&gt;0; row--){
          for(int j=1; j&lt;=2*n; j++){
              if(j&lt;=row||j&gt;=(2*n)-row){
                  cout&lt;&lt;&quot;*&quot;;
              
              }
              else{
                  cout&lt;&lt;&quot; &quot;;
              }
          }
          cout&lt;&lt;endl;
      }
      return 0;
  }
  </code></pre>
  <p>but I couldn't get the desired result. What could be the reason?</p>