C++ Write the function isEven() that receives an integer type parameter and retu
ID: 3834856 • Letter: C
Question
C++
Write the function isEven() that receives an integer type parameter and returns a boolean type. The function returns true if the parameter is an even integer and false otherwise. Test this function by writing code for parts (a) and (b) below
Write a main function in which the user is prompted to enter ten integer type numbers. Use an array to store the numbers. You must also use a loop to receive the ten numbers from the user.
After receiving the integers from the user in part (a), call the function isEven() on each integer in the array and display only the even integers. You must write a loop for this part.
Example: user enters: 4 3 8 10 7 43 57 12 9 100 then the output should be: 4 8 10 12 100
Explanation / Answer
#include <iostream>
using namespace std;
bool isEven(int x){
return x%2==0;
}
int main() {
// your code goes here
cout << "Enter 10 integers"<<endl;
int arr[10];
//Loop to read the 10 integers
for(int i=0;i<10;i++){
cin >> arr[i];
}
//Loop to check whether the element is even or not
for(int i=0;i<10;i++){
if(isEven(arr[i])){
cout << arr[i] << " ";
}
}
return 0;
}
OUTPUT :
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.