Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
2年前关闭。
我正在努力实现目标。
只是尝试使用printf(“ **** \ n ***** \ n ***** \ n”);并且不起作用。
有人可以帮我吗?
抱歉,我的问题写得不好。
example for 1 input : 5
该算法类似于对一个int矩阵的所有数字求和。
题:
主要代码:
想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
2年前关闭。
我正在努力实现目标。
只是尝试使用printf(“ **** \ n ***** \ n ***** \ n”);并且不起作用。
有人可以帮我吗?
抱歉,我的问题写得不好。
example for 1 input : 5
该算法类似于对一个int矩阵的所有数字求和。
题:
*****
*****
*****
*****
*****
*****
if input : 2
*****
*****
*****
***** *****
***** *****
***** *****
*****
*****
*****
if input : 3
主要代码:
#include <stdio.h>
int main()
{
int rows, cols, i, j, k;
/* Input rows and columns from user */
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
k = 1;
for(i=1; i<=rows; i++)
{
for(j=1; j<=cols; j++)
{
if(k == 1)
{
printf("111\n111\n111");
}
else
{
printf("0");
}
// If k = 1 then k *= -1 => -1
// If k = -1 then k *= -1 => 1
k *= -1;
}
if(cols % 2 == 0)
{
k *= -1;
}
printf("\n");
}
return 0;
}
最佳答案
int main()
{
int rows, cols, i, j, k,l;
/* Input rows and columns from user */
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
k = 1;
for(i=1; i<=rows; i++)
{
for(l=1; l<=3; l++)
{
for(j=1; j<=cols; j++)
{
if(k==1){
if(j%2==1){
printf("***");
}
else{
printf(" ");
}
}
else{
if(j%2==1){
printf(" ");
}
else{
printf("***");
}
}
}
printf("\n");
if(l==3)
k=(-1)*k;
}
}
return 0;
}
关于c - 如何在C中制作棋盘图案? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49526916/