Question

In: Computer Science

Write a function name as 'checkEvenOrOdd' that checks the input value is odd or even number....

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

Solutions

Expert Solution

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:


Related Solutions

Counts the number of odd, even, and zero digits in an integer input value. Repeat until...
Counts the number of odd, even, and zero digits in an integer input value. Repeat until user does not want to continue. Develop the program in an incremental fashion. For example, write the part of the program, which inputs a single integer value and displays number of odd, even, and zero digits in that number. Submit your partial program for grading to make sure it works for the first few test cases. Below is an example execution of a partial...
Write c code to determine if a binary number is even or odd. If it is...
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Develop a C++ function to find the number of even and odd integers in a given...
Develop a C++ function to find the number of even and odd integers in a given array of integers Pass in an array of integers Pass in the size of the array of integers Pass in a reference parameter for the number of even values Pass in a reference parameter for the number of odd values The function doesn't return anything Develop a C++ program to test your function
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The...
Even Odd Average (C++ LANGUAGE) Write the following functions: Function #1 Write the function Print. The function will have one int 1D array n and one int size as parameters. The function will display all the values of n on one line. Function #2 Write the function AverageEvenOdd. The function will have one int 1D array n and one int size as parameters. The size of the array is given by the parameter int size. Therefore, the function should work...
*Code in C* Write a function that checks if a number is a perfect cube. Write...
*Code in C* Write a function that checks if a number is a perfect cube. Write another function that calculates the integer cubic root. Under the main program: Prompt the user to input a number Tell the user if the number is a perfect cube or not Print the cubic root if the inputted number is a perfect cube.
Prove that every natural number is odd or even.
Prove that every natural number is odd or even.
determine whether the given function is even, odd, or neither. Please write a code in MatLab...
determine whether the given function is even, odd, or neither. Please write a code in MatLab to solve this problem below: 1.f(x) = sin 3x please only use Matlab to solve this problem
A function is odd function if f (-x) = - f(x). A function is even function...
A function is odd function if f (-x) = - f(x). A function is even function if f(-x) = f(x). f(x) = sin (x) and f(x) = x are examples of odd functions and f(x) = cos x and f(x) = e^ (-x)^2 are examples of even functions. Give two more examples of even functions and two more examples of odd functions. Show that for odd functions f (x), integral of f(x) from negative infinity to infinity = 0 if...
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without...
Using for loop . Input an integer and identify whether it's EVEN OR ODD ( without using modulo operator ) using only <iostream> . C++ programming
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT