用c语言编程:输出国际象棋棋盘
时间: 2024-05-05 13:18:24 浏览: 7
Sure, below is a sample code in C for printing an international chess board:
```
#include <stdio.h>
int main()
{
int i, j;
// printing the white squares of chess board
for(i=1; i<=8; i++)
{
for(j=1; j<=8; j++)
{
if((i+j)%2 == 0)
{
printf("##");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
Please note that this is just a sample code and there are multiple ways to print a chess board in C.
相关问题
用c语言输出国际象棋棋盘
以下是用C语言输出国际象棋棋盘的代码:
```
#include <stdio.h>
int main()
{
char chessboard[8][8] = {
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'},
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
{' ', '.', ' ', '.', ' ', '.', ' ', '.'},
{'.', ' ', '.', ' ', '.', ' ', '.', ' '},
{' ', '.', ' ', '.', ' ', '.', ' ', '.'},
{'.', ' ', '.', ' ', '.', ' ', '.', ' '},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'}
};
printf(" a b c d e f g h\n");
for (int i = 0; i < 8; i++) {
printf("%d ", 8 - i);
for (int j = 0; j < 8; j++) {
printf("%c ", chessboard[i][j]);
}
printf("%d", 8 - i);
printf("\n");
}
printf(" a b c d e f g h\n");
return 0;
}
```
输出结果:
```
a b c d e f g h
8 R N B Q K B N R 8
7 P P P P P P P P 7
6 . . . . 6
5 . . . . . 5
4 . . . . 4
3 . . . . . 3
2 p p p p p p p p 2
1 r n b q k b n r 1
a b c d e f g h
```
棋盘由一个8x8的字符数组表示,其中空格表示空白,点号表示黑色方格。棋子用字母表示,大写字母表示白方,小写字母表示黑方,分别对应国际象棋规定的棋子名称。棋盘上的行和列用数字和字母表示。输出时先输出列标,然后逐行输出棋盘。
c语言编程:输出100~200之间的能被5整除的数,输出要有一定的文字说明。
以下是使用C语言编写的程序,可以输出100~200之间的能被5除的数,并且会有相应的文字说明:
```
#include <stdio.h>
int main() {
printf("以下是100~200之间能被5整除的数:\n");
for (int i = 100; i <= 200; i++) {
if (i % 5 == 0) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}
```
程序首先输出一行文字说明,然后使用for循环遍历100~200之间的所有数,如果当前数能被5整除,就输出它。最后再输出一个换行符。