/*
Example on two-dimensional arrays. 
We read the array, print it, find the sum, average, and maximum.
*/
#include <iostream>
#include <iomanip> //needed for setw
using namespace std;
int main()
{
	const int rows = 2;
	const int cols = 3;
	float sum = 0, max;
	int i, j;
	float a[rows][cols];

	// Read the array
	cout << "Enter " << rows * cols << " real numbers "
		<< "distributed on " << rows << " rows with "
		<< cols << " elements per row:\n";
	for (i = 0; i < rows; i++)
		for (j = 0; j < cols; j++)
			cin >> a[i][j];
	
	// Print the array
	cout << "The array is: \n";
	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < cols; j++)
			cout << setw(5) << a[i][j];
		cout << endl;
	}
	cout << endl;

	// Find the sum of the array
	sum = 0;
	for (i = 0; i < rows; i++)
		for (j = 0; j < cols; j++)
		sum += a[i][j];
	
	// Find the average of the array and print it
	cout << "The average is: " << sum / (rows * cols) << endl;


	// Find the maximum of the array
	max = a[0][0];
	for (i = 0; i < rows; i++)
		for (j = 0; j < cols; j++)
			if (a[i][j] > max)
				max = a[i][j];

	// Print the maximum
	cout << "The maximum is: " << max << endl;

	return 0;
}
