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
c++
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.
- Get input
a
. - Store
a % 2
asb
. - If
b
is 0, thenb
is even, elseb
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