qfedu-basic-level/day8/d10.cpp

41 lines
794 B
C++

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int rows = 1;
cout << "请输入行数: ";
cin >> rows;
int arr[rows][3] = {}; // ?变量是否可以作为定义数组时的维度
int num;
int j = rows;
while (j)
{
for (int i = 0; i < 3; i++)
{
cout << "请输入值: ";
cin >> arr[rows - j][i];
// break 结束 for 循环
// 如何结束外部的 while 循环
if (arr[rows - j][i] == -1)
// break;
goto show;
}
j--;
}
show:
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < 3; j++)
{
cout << arr[i][j] << "\t";
}
cout << endl;
}
return 0;
}