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
Post a Comment