传送多维数组

#include     
#include     
using namespace std;


//double average(double* array,int count);  //function prototype
double yield(double values[][4], int n);
int main()
{
	double beans[3][4] = {
		{ 1.0, 2.0, 3.0, 4.0 },
		{ 5.0, 6.0, 7.0, 8.0 },
		{ 9.0, 10.0, 11.0, 12.0 }
	      };
	cout << endl
		<< "Yield=" << yield(beans, sizeof beans / sizeof beans[0])
		<< endl;
	   return 0;
}

double yield(double array[][4], int count)
{
	double sum=0;
	for (int i = 0; i < count; i++)
	for (int j = 0;j < 4; j++)
	{
		sum += array[i][j];
	      //sum += *(*(array+i)+j);
	}
	return sum;
}
  

你可能感兴趣的:(传送多维数组)