Answer:
#include <iostream>
using namespace std;
void filterEvens(int myArray[]) {
for (int i = 0; i < 8; ++i) {
if(myArray[i]%2==0){
cout<<myArray[i]<<" ";
}
}
}
int main(){
int myArray[8];
for(int i =0;i<8;i++){
cin>>myArray[i];
}
filterEvens(myArray);
return 0;
}
Explanation:
The solution is provided in C++
#include <iostream>
using namespace std;
The function filerEvens is defined here
void filterEvens(int myArray[]) {
This iterates through the elements of the array
for (int i = 0; i < 8; ++i) {
This checks if current element is an even number
if(myArray[i]%2==0){
If yes, this prints the array element
cout<<myArray[i]<<" ";
}
}
}
The main begins here
int main(){
This declares an integer array of 8 elements
int myArray[8];
The following iteration allows input into the array
<em> for(int i =0;i<8;i++){</em>
<em> cin>>myArray[i];</em>
<em> }</em>
This calls the defined function filter Evens
filterEvens(myArray);
return 0;
}