Even Odd without If Else Statement

This is a simple  Program in C++ for finding if a given number is Even or Odd without IF. This is a part of Mumbai University MCA Colleges. 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.


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a comment