This is probably really easy question.
How may I find in C++ if the number is even or odd?
Thanks

Member Avatar for iamthwee

Hint: Use the modulus operator "%"

When you divide by 2 and the remainder is 0, the number's even.

if ( x % 2 == 0 ) {
  // even
} else {
  // odd
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.