我有一个赋值使用嵌套for循环来打印5行和3列的二维数组的索引,而不使用数组。关于嵌套for循环
#include <iostream>
using namespace std;
int main()
{
int row;
int column;
cout << "Counting with nested loops: indices of row, column" << endl << endl;
for (row = 1; row <= 5; row++)
{
for (column = 1; column <= 3; column++)
{
}
cout << row << "," << column << "\t" << row << "," << column << "\t" << row << "," << column << "\t" << endl;
}
cout << "\n\n\n" << endl;
return 0;
}
这是我到目前为止的代码。我的目标是打印
1,1 1,2 1,3
2,1 2,2 2,3
等。当我运行该程序将打印
1,4 1,4 1,4
2,4 2,4 2,4
所以我行部分正确。任何人都可以帮我弄清楚我的错误是什么?
如果没有数组,将会打印什么? –
那么你的数据存储在哪里? –
@AndreasWalter我相信这个问题很清楚:“打印出二维数组的索引” - 他必须打印数组的索引而不是内容。也许有人说过他们实际上的意思时,也是少数几次之一。 :) – davmac