In: Computer Science
Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number. The main function is given:
int main(){
int number;
cout << "Check number input: ";
cin >> number;
cout << "The input number " << number << " is " << checkEvenOrOdd(number) << endl;
return 0;
}
simple c++ code please
The function checkEvenorOdd() is highlighted in the following code
% gives the remainder. If n%2 gives remainder 0 then it is even else it is odd
Code:
#include <iostream>
using namespace std;
char* checkEvenOrOdd(int
n){
if(n % 2 == 0)
return "Even";
else
return "Odd";
}
int main(){
int number;
cout << "Check number input: ";
cin >> number;
cout << "The input number " << number << " is "
<< checkEvenOrOdd(number) << endl;
return 0;
}
Sample O/P1:
Check number input: 23
The input number 23 is Odd
Sample O/P2:
Check number input: 16
The input number 16 is Even
Code Screenshot:
Sample O/P1 screenshot:
Sample O/P2 screenshot: