生成一个C语言的俄罗斯方块代码
时间: 2023-03-10 17:53:08 浏览: 62
#include <stdio.h>
int main()
{
int i, j, k;
int rows, columns;
int flag;
printf("Enter number of rows and columns of the game : ");
scanf("%d %d", &rows, &columns);
// Outer loop to print rows
for (i = 0; i < rows; i++) {
// Inner loop to print columns
for (j = 0; j < columns; j++) {
// Flag to check whether to print star or space
flag = 0;
// Check if any row is divisible by 4
if (i % 4 == 0)
flag = 1;
// Check if any column is divisible by 4
else if (j % 4 == 0)
flag = 1;
// Print star for flag = 1 else print space
if (flag == 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}