Answer to Question #212375 in C++ for thanksforyourhelp

Question #212375

Write a main program to run the following functions:


void inp

ut_array(double a[ ]); // to input an array


void count( double a[ ], int &odd, int &even) // count odd and even numbers, return by

reference


1
Expert's answer
2021-07-01T05:39:46-0400
#include <iostream>
using namespace std;


void input_array(double a[]); // to input an array
void count(double a[], int &odd, int &even); // count odd and even numbers, return by reference


const int N = 5;
int main() {
    double a[N];


    cout << "Input " << N << " real numbers" << endl;
    input_array(a);
    int odd, even;
    count(a, odd, even);
    cout << "You have entered " << odd << " odd and " << even << " even numbers." << endl;
}


void input_array(double a[]) {
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
}


void count(double a[], int &odd, int &even) {
    odd = even = 0;
    for (int i=0; i<N; i++) {
        int x = static_cast<int>(a[i]);
        if (x % 2 == 0) {
            even++;
        }
        else {
            odd++;
        }
    }
}

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
New on Blog
APPROVED BY CLIENTS