objective c - Star Pattern Logic -


i want make star pattern this.

    *   * * * * * * * *   * * *     * 

i using code.

for (int i=1; i<=3; i++) {         (int j=1; j<=3-i; j++) {             printf(" ");         }         (int k=1; k<=2*i-1; k++) {             printf("x");         }         printf("\n");     } 

this give

     *    * * *  * * * * * 

how iterate in decrement order.

 when using  (int i=3; i>=0; i--) {         (int j=1; j<=3-i; j++) {             printf(" ");         }         (int k=1; k<=2*i-1; k++) {             printf("x");         }         printf("\n");     }  xxxxx  xxx   x 

how merged it?

another logic here

int x=11; int y=x/2; int z=1;  bool b1=true; bool b2= true; for(int i=0;i<x;i++) {     for(int j=0;j<y;j++)     {         printf(" ");     }     for(int k=0;k<z;k++)     {         printf("*");     }     if(y==0) b1=false;     if(z==x) b2=false;      y=b1?y-1:y+1;     z=b2?z+2:z-2;     printf("\n"); } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -