0

Did i return this array properly

I have to create an array of random numbers, write a function that takes the array as an argument and return only even numbers, while using the function in the program. I used what I think is the passing array method, but I'm not sure if I've done it as I was instructed. Any advice is greatly appreciated. #include <iostream> #include <cstdlib> #include <ctime> using namespace std; void evenOnly (int [], int); int main() {    srand(time(NULL));    int numbers[5];    int length = 5;    evenOnly(numbers, length);    return 0; } //srand(time(NULL));    void evenOnly(int numbers[], int length) {        for (int i = 0; i < length; i++) {            numbers[i] = (rand() % 170) + 1;        if(numbers[i] % 2 == 0) {            cout << numbers[i] << endl;        }    } }

22nd Nov 2018, 11:57 PM
dominic smith
dominic smith - avatar
1 Respuesta
0
thanks a lot. I believe the point of the assignment is to use pointers. Your way allows me to return the array as an argument, while my way passes the array, I think?
23rd Nov 2018, 5:53 PM
dominic smith
dominic smith - avatar