Check Even or Odd Using Function
C++
Easy
6 views
Problem Description
Create function that checks if number is even or odd.
Real Life: Like categorizing numbers automatically.
Step-by-Step Logic:
1. Function takes one number as parameter
2. Check if number divides by 2 completely
3. Return true if even, false if odd
4. Use return value to print result
Official Solution
bool isEven(int number) {
if(number % 2 == 0) {
return true;
} else {
return false;
}
}
void function_q2_even_odd() {
int num = 17;
if(isEven(num)) {
cout << num << " is Even" << endl;
} else {
cout << num << " is Odd" << endl;
}
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!