C实例---打印菱形

时间:2022-09-09 19:30:42

代码:

#include <stdio.h>
#define ROW 11 //行数,必须为大于1的奇数

int main ()
{
    int i,j;
    for (i = 0; i <= ROW / 2; i ++)
    {
        for (j = 0; j <= ROW / 2 - (1 + i); j ++)
            printf(" ");

        for (j = 0; j <=2 * i; j ++)
            printf("*");
        printf("\n");
    }
    for (i = 0; i <= ROW / 2 - 1; i ++)
    {
        for (j = 0; j <= i; j ++)
            printf(" ");
        for (j = 0; j <= 2 * (ROW / 2 - 1 - i); j ++)
            printf("*");
        printf("\n");
    }


    return 0;
}

运行效果:
C实例---打印菱形