题主考虑的复杂了点,修改如下,供参考:
#include <stdio.h>
#define ch "■"
int main()
{
int i, j, n = 8;
scanf("%d", &n);
for (i = 0; i < n; i++){
for (j = i; j < n + i; j++)
printf("%2s", j % 2 == 0 ? ch : " ");
printf("\n");
}
return 0;
}