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)
1
Expert's answer
2012-11-30T05:12:52-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS