Odd or Even: Mrs. Anitha , our favourite Maths teacher wanted to teach her students to check whether the given number is odd or even.
Write a program to accept an integer and to check whether the given number is odd or even using functions and pointers.
Note: Print the text “a is an odd number ” and “a is an even number” inside the function.
Function Specification:
void oddoreven(int *a)
This function prints the text “a is an odd number” if the number is odd, else prints “a is an even number” if the number is even.
Input Format:
The input consists of an integer.
Output Format:
Refer to the sample input and output for formatting details.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output1:
Enter the number
5
5 is an odd number
Sample Input and Output2:
Enter the number
6
6 is an even number
Function Definitions:
| void oddoreven (int *) |
Solution
#include <iostream>
using namespace std;
void oddoreven(int *a)
{
if (*a % 2 == 0)
cout << *a << " is an even number" << endl;
else
cout << *a << " is an odd number" << endl;
}
int main()
{
int a;
cout << "Enter the number" << endl;
cin >> a;
oddoreven(&a);
return 0;
}Happy Learning – If you require any further information, feel free to contact me.
![[Solved] Odd or Even with C++ [Solved] Odd or Even with C++](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Odd-or-Even-with-C.png)
![[Solved] Pairing the brackets Contest Problem](https://realcoder.techss24.com/wp-content/uploads/2022/09/Solved-Pairing-the-brackets-Contest-Problem-300x200.png)
![[Solved] Character Pattern 8 with C++](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Character-Pattern-8-with-C-300x200.png)
![[Solved] Count Subarrays With Score Less Than K LeetCode Contest Problem](https://realcoder.techss24.com/wp-content/uploads/2022/06/Solved-Count-Subarrays-With-Score-Less-Than-K-LeetCode-Contest-Problem-300x200.png)