Printing out characters in an X pattern using for loops

后端 未结 4 1274
小蘑菇
小蘑菇 2021-01-21 14:05

I\'m trying to print this big X pattern:

 x       x
  x     x
   x   x
    x x
     x
    x x
   x   x
  x     x
 x       x

I can\'t figure out

4条回答
  •  悲&欢浪女
    2021-01-21 14:35

    For a little bit of fun:

    int main (void)
    {
        int i;
        int w = 7;
        for (i=1;i<=w*(w+1);i++)
            printf (
                "%c",
                i % (w+1) == 0 ? '\n' : 
                i % (w) == 0 || i % (w+2) == 1 ? '*' : ' ');
    
    }
    

提交回复
热议问题