Even Odd without If Else Statement

Ram Pothuraju




This is a simple  Program in C++ for finding if a given number is Even or Odd without IF.  This is a interview Question and Program




EVEN ODD WITHOUT IF
This program will help you find even or a odd number without using the if statement.
This program is mostly asked in interviews and should be taken seriously.

#include <stdio.h>
#include <string.h>
int main()
{
string show[] = {"even", "odd"};
int a=6;
cout<<"the number "<<a<<" is "<<show[a%2];
return 0;
}









As you can see I have just used the String array to store the output. The array starts with index 0.
When I am Displaying Show[a%2], the output will be either 1 or 0. If its Zero then we need to print Even and if its 1 then Odd.
Using a simple logic we can get the even odd without if.


Tags

Post a Comment

0Comments

Post a Comment (0)