Read the question, write C++ on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read one integer. Print even or odd (lowercase).
The modulo operator % gives the remainder — the classic even/odd test.
Input. One line: an integer (may be negative).
Output. The word even or odd.
Examples
Input
4
Output
even
Input
7
Output
odd
Hint
- n % 2 == 0 is true for even numbers.
- A ternary is compact: (n % 2 == 0 ? "even\n" : "odd\n").
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
int main() {
int n;
std::cin >> n;
std::cout << (n % 2 == 0 ? "even\n" : "odd\n");
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.