Write a program to add data from two arrays of 2X2 dimension. The arrays must be of double type to process students scores. After addition the program calculates the average of scores from each array. Then the averages are added to get the total of the averages
#include <iostream>
using namespace std;
int main()
{
double A[2][2];
double B[2][2];
double sum, aver1, aver2;
sum = 0;
cout << "Enter values for first array (2 3 4 5): ";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cin >> A[i][j];
sum += A[i][j];
}
}
aver1 = sum / 4;
sum = 0;
cout << "Enter values for second array (2 3 4 5): ";
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
cin >> B[i][j];
sum += B[i][j];
}
}
aver2 = sum / 4;
cout << "Average of first array is: " << aver1 << endl;
cout << "Average of second array is: " << aver2 << endl;
cout << "Total of averages is: " << aver1 + aver2 << endl;
system("pause");
return 0;
}
Comments
Leave a comment