I'm stuck on an exercise about using printf
only to draw a zig-zag pattern in console, the output should be:
* *
* * * *
* * * *
* * *
Here is my code:
int main(int argc, const char * argv[]) {
@autoreleasepool {
int n,i,j;
printf("Input the height:");
scanf("%d",&n);
printf("\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
printf(" ");/
for(j=1;j<=2*i;j++)
{
if (j==1||j==2*i-1)
printf("*");
else
printf (" ");
}
printf("\n");
if (i==n) {
for(j=1; j<=n;j++)
printf (" ");
break ;
}
}
}
}
like this. I'm trying to draw 2 sides of a triangle, but still don't know how to draw.