#include <iostream>
#include <conio.h>
using namespace std;
#define& ROWS 3
#define COLS 4
void printAverages(int (&arr)[ROWS][COLS])
{
double oddSum = 0;
double evenSum = 0;
int oddCount = 0;
int evenCount = 0;
for (int r = 0; r < ROWS; r++)
& for (int c = 0; c < COLS; c++)
& if (arr[r][c] % 2 == 0)
& {
& evenCount++;
& evenSum += arr[r][c];
& }
& else
& {
& oddCount++;
& oddSum += arr[r][c];
& }
&
cout.width(5);
cout.precision(2);
cout << "The average of odd numbers is: " << oddSum / oddCount << endl;
cout << "The average of even numbers is: " << evenSum / evenCount;
}
void main()
{
int array[ROWS][COLS] = { {2, 67, 13, 55},
& {90, 19, 24, 1},
& {32, 47, 25, 88} };
printAverages(array);
getch();
}
Comments
Leave a comment