我试图将一个二维数组转换为一维数组。
我对C/C++非常陌生,但我认为学习如何将二维数组转换为一维数组非常重要。
所以在这里,我遇到了这个问题。
目前我的代码是: http://ideone.com/zvjKwP
我在认为自己失败的地方留下了评论。 我必须限制进入一维数组的数字,其值的平方大于50。 但是我肯定必须解决2D=>1D转换的问题。 你能帮我吗?
目前我的代码是: http://ideone.com/zvjKwP
#include<iostream>
using namespace std;
int main()
{
int n=0,m=0; // 2D array nRow, nCol
int a[n][m];
int i,j; // цикъл въвеждане 2D
int q,p,t; // for 2D=>1D
int b[100];
int r; // for cout
cout<<"Enter the array's number of rows and columns: ";
cin>>n>>m;
// entering values for the 2D array
for (i = 0;i<=n;i++)
{
for (j = 0;j<=m;j++)
{
cout<<"a["<<i<<"]["<<j<<"]="<<endl;
cin>>a[i][j];
cin.ignore();
}
}
// Most likely the failzone IMO
for (q = 0;q<=i;q++)
{
for (t = 0;t<=i*j+j;t++)
{
b[t] = a[i][j];
}
}
// attempting to print the 1D values
cout<<"The values in the array are"<<"\n";
for(r=0;r<=t;r++)
{
cout<<"b["<<r<<"] = "<<b[r]<<endl;
}
cin.get();
return 0;
}
我在认为自己失败的地方留下了评论。 我必须限制进入一维数组的数字,其值的平方大于50。 但是我肯定必须解决2D=>1D转换的问题。 你能帮我吗?