title: C programming - asterisk-shape
body: <p>Hi I want to print shapes like this with *.
  The height of this shape is 6 and if entering another even integer as height, it will produce  a shape with that height. </p>
  
  <p><img src="https://i.stack.imgur.com/GnS9z.png" alt="enter image description here"></p>
  
  <p>So far I am doing this, but this failed.....
  Would anyone tell me where I am doing wrong? Thank you!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main ()
  {
      int height;
      int i, j;
  
      printf("Please input height with an even integer ");
      scanf("%d", &amp;height);
  
      for (i=height/2; i&gt;=1; i--)
      {
  
          for (j=1; j&lt;=height; j++)
          {
              if (i==height/2)
                  printf("*");
              else if (j=i || j==(height-(i-1)))
                  printf("*");
              else
                  printf(" ");
          }
  
          printf("\n");
      }
  
      system("PAUSE");
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks everyone!</p>
  
  <p>Actually I tried another method earlier and it worked out.</p>
  
  <p>I printed out the top line and the bottom line first and put asterisks and space to where it should be. </p>
  
  <p>Here is my solution.</p>
  
  <pre><code>void printStar(int x);
  
  int main(int argc, char *argv[])
  {
          int height, value = 2 , value2;
  
          printf("Please input height with an even integer ");
          scanf("%d", &amp;height);
  
          value2 = height-1;
  
          for (int i=1; i&lt;=height; i++)
          {
  
           if(i==1){
  
                 printStar(height);
  
           }else if(i == height){
  
                 printStar(height);
  
           }else{
  
                 for(int y = 1 ; y&lt;=height ; y++){
  
                      if(value == y || value2 == y){
  
                           printf("*");           
  
                      }else{
  
                           printf(" ");   
  
                      }
  
                 }
                  value++;
                  value2--;       
  
           }  
           printf("\n");
          } 
  
  
      system("PAUSE");
      return 0;
  }
  
  void printStar(int x){
       for(int i = 0 ; i&lt;x ;i++){
            printf("*");  
       }
  
  }
  </code></pre>