读书人

二维数组作为函数参数出现有关问题

发布时间: 2012-03-11 18:15:39 作者: rapoo

二维数组作为函数参数出现问题
我想通过这个函数把一维数组中的数据放到二维数组中,在vc中出现在下述错误void One_To_Two(int floor,int room,double one[],double two[][])
{
// int k=0;
// for(int i=0;i <floor;i++)
// for(int j=0;j <room;j++)
// two[i][j]=one[k++];

}
error C2087: ' <Unknown> ' : missing subscript

请问如何修改?


[解决办法]
#include "stdafx.h "
#include "iostream.h "
const int N = 100;

void One_To_Two(int floor, int room, double one[], double two[][N])
{
int k = 0, i, j;

for(i = 0; i < floor; i++)
{
for(j = 0; j < room; j++)
{
two[i][j] = one[k++];
cout < <two[i][j] < < " ";
}
cout < <endl;
}
}

int main(int argc, char* argv[])
{
int a,b,c;
double one[N] = {0},two[N][N] = {{0,0}};

cout < < "请输入一维数组的大小: ";
cin> > c;
cout < < "请输入具体的数字: ";
for(int i = 0; i < c; i++)
{
cin> > one[i];
}

cout < < "请输入二维数组的行数和列数: ";
cin> > a> > b;

One_To_Two(a,b,one,two);

return 0;
}

读书人网 >C++

热点推荐