65 719
Assignments Done
99,2%
Successfully Done
In October 2018

Answer to Question #19739 in C++ for zaima

Question #19739
write a program using a user definded function where two dimensional array of number and it will give us average of odd and even number. ( use call by reference)
Expert's answer
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions