How to solve this problem without the use of if-else statements?

Posted by kira on Programmers See other posts from Programmers or by kira
Published on 2012-06-02T16:51:17Z Indexed on 2012/06/02 22:49 UTC
Read the original article Hit count: 203

Filed under:

I have just started my C++ lecture class. And the teacher has given us the following assignment.

Write a program that determines whether a number is even or odd.

The logic I would use for the program is.

  1. Get input a.
  2. Store a % 2 as b.
  3. If b is 0, then b is even, else b is odd.

The catch though, is that we have to write the program without the use of a if-else statement.

I have been thinking on how to approach the problem for the past few hours, but I have no clue what to do. Any hints or suggestions?

© Programmers or respective owner

Related posts about c++