/*
Declare a two-dimensional array of two rows and 3 columns of type int, and 
find the average of the array and the average of each row of the array. 
Then print the array neatly.
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	int a[2][3], i, j;
	float sum = 0;
	// Read th array
	cout << "Enter the array: \n";
	for (i = 0; i < 2; i++)
		for (j = 0; j < 3; j++)
			cin >> a[i][j];
	cout << "The array is: " << endl;
	// Print the array neatly
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 3; j++)
			cout << setw(7) << a[i][j];
		cout << endl;
	}
	cout << endl;
	
	// Find the sum of the arry
	for (i = 0; i < 2; i++)
		for (j = 0; j < 3; j++)
			sum += a[i][j];
	cout << "Average of the array: " << sum / 6 << endl; 
	
	// Find average of 1st row
	sum = 0;
	for (j = 0; j < 3; j++)
		sum += a[0][j];
	cout << "Average of 1st row: " << sum / 3 << endl;
	
	// Find average of 2nd row
	sum = 0;
	for (j = 0; j < 3; j++)
		sum += a[1][j];
	cout << "Average of 2nd row: " << sum / 3 << endl;
	
	// Find average of all rows at once
	for (i = 0; i < 2; i++)
	{
		sum = 0;
		for (j = 0; j < 3; j++)
			sum += a[i][j];
		cout << "Average of " << i+1 <<"th row: " 
			<< sum / 3 << endl;
	}
	return 0;
}

