-3
私はCの新人です。チェス盤のパターンを出力するプログラムを作ろうとしています。しかし、私は次のステップが何になるのか分かりません。誰も私にこれを手伝ってもらえますか?Cでチェス盤を作る方法は?
メイン:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int main() {
int length,width;
enum colors{Black,White};
printf("Enter the length:\n");
scanf("%d",length);
printf("Enter the width:\n");
scanf("%d",width);
int board[length][width];
createBoard(length,width);
for(int i =0;i< sizeof(board);i++) {
if(i%2==0) {
// To print black
printf("[X]");
}
else {
// To print white
printf("[ ]");
}
}
} //main
CreateBoard機能:
int createBoard(int len, int wid){
bool b = false;
for (int i = 0; i < len; i++) {
for (int j = 0; j < wid; j++) {
// To alternate between black and white
if(b = false) {
board[i][j] = board[White][Black];
b = false;
}
else {
board[i][j] = board[Black][White];
b = true;
}
}
}
return board;
}
C++よりもC++に似ています。注意してC++タグを削除しますか? –