C++ 寻找每个奇j索引的多维数组模式
好的,我试着为每一个奇数的j(包括0)插入一个空格字符,问题是0算作偶数(我希望它算作奇数,这样就可以放置一个空格字符),我正在努力寻找解决方案,而不是玩奇数或偶数的j。目标是使数组中的每个元素都有一个字母,并为下一个索引提供一个空格字符。此函数负责填充阵列C++ 寻找每个奇j索引的多维数组模式,c++,arrays,multidimensional-array,C++,Arrays,Multidimensional Array,好的,我试着为每一个奇数的j(包括0)插入一个空格字符,问题是0算作偶数(我希望它算作奇数,这样就可以放置一个空格字符),我正在努力寻找解决方案,而不是玩奇数或偶数的j。目标是使数组中的每个元素都有一个字母,并为下一个索引提供一个空格字符。此函数负责填充阵列 void createBoard(char arr [DIM][DIM], int size){ //ASCII number for capital A char x = 65; for(int i = 0; i<s
void createBoard(char arr [DIM][DIM], int size){
//ASCII number for capital A
char x = 65;
for(int i = 0; i<size; i++){
for(int j = 0; j<size; j++){
if(j%2==0){
arr[i][j] = x++;
}
else{
arr[i][j] = 32;
}
cout << "Element at x[" << i << "][" << j << "]: ";
cout << arr[i][j] << endl;
}
}
}
void createBoard(字符arr[DIM][DIM],整数大小){
//大写字母A的ASCII数字
charx=65;
for(int i=0;ichar x='A'
将避免使用该注释。if(j%2==0&&j!=0).
。这实际上“将0计为奇数”
const int DIM = 7;
int main()
{
char arr [DIM][DIM];
int bsize;
char answer;
do{
cout << "Please enter the size of the board [1-7]: ";
cin >> bsize;
if(!cin){
cout << endl << "Invalid entry";
break;
}
if (bsize<=DIM && bsize>=1){
createBoard(arr,bsize);
}
else{
cout << endl << "Invalid size";
cout << endl << "Do you want to try again [y-n]?: ";
cin >> answer;
}
// As long as the answer is 'y' (in upper or lower case), keep looping
}while(answer=='Y'||answer=='y');
return 0;
}