所以我需要想出这样的事情:这是飞机座位的布局。
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
但我的代码打印出来了:
ABCD
ABCABCD
ABCABCD
ABCABCD
ABC
这是我的代码,任何帮助都会非常感激。我刚开始使用数组
#include <iostream>
using namespace std;
int main ()
{
char airplane[7][4] = {{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'}};
for (int i=0; i<4; i++)
{
for (int j=0; j<7; j++)
{
cout<<airplane[i][j];
if (airplane[i][j]=='D')
{
cout<<endl;
}
}
}
system ("PAUSE");
return 0;
}
答案 0 :(得分:0)
试试这个..: - &gt;
#include <iostream>
using namespace std;
int main ()
{
char airplane[7][4] = {{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'}};
for (int i=0; i<7; i++) //Row
{
cout<<i+1;
for (int j=0; j<4; j++) //Column
{
cout<<airplane[i][j];
cout<<" ";
}
cout<<endl;
}
system ("PAUSE");
return 0;
}
答案 1 :(得分:0)
这里是代码:
#include <iostream>
using namespace std;
int main ()
{
char airplane[7][4] = {{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D'}};
for (int i=0; i<7; i++)
{
cout << i+1;
for (int j=0; j<4; j++)
{
cout<<airplane[i][j];
if (airplane[i][j]=='D')
{
cout<<endl;
}
}
}
system ("PAUSE");
return 0;
}
答案 2 :(得分:0)
以这种方式更改for循环
for (int i=0; i<7; i++)
{
cout<<i+1;
for (int j=0; j<4; j++)
{
cout<<' ';
cout<<airplane[i][j];
}
cout<<endl;
}
答案 3 :(得分:0)
尝试运行外循环7次,内循环运行4次。包括cout&lt;
顺便提一下,如果你把每行的座位数改为5,那么Bui Akinori给出的代码就是错误的。