title: how to create a pyramid using for loop in c++
body: <p>Hello guys I just want to ask how can I create a triangle using c++?</p>
  
  <p>Actually I have my code but I don't have an idea how to center the first asterisk in the triangle. My triangle is left align. How can I make it a pyramid? </p>
  
  <p>Here's my code below. </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main(){
  
      int x,y;
      char star = '*';
      char space = ' p ';
      int temp;   
  
      for(x=1; x &lt;= 23; x++){ 
  
          if((x%2) != 0){
  
              for(y=1; y &lt;= x ; y++){     
  
                  cout &lt;&lt; star;
              }
  
              cout &lt;&lt; endl;           
          }       
      }
  
      return 0;
  }
  </code></pre>