# Check whether a number is even or odd

I know this is a very simple task but I want you to read further. It won’t take long.

To check whether a number is even or odd, you need to divide the number by 2 and check the remainder. The number is even if the remainder is 0 and odd if the remainder is 1. Here is a C++ program to do this using if-else:

#include <iostream>

using namespace std;

int main()

{

int n;

cin>>n;

if(n%2 == 0) cout<<”Even”;

else cout<<”Odd”;

return 0;

}

Pretty simple, isn’t it? But can you do with without using if-else? Yes, that is possible. Our outcomes will be either 0 or 1. Create a string array and store the strings “Even” and “Odd” at 0th and 1th index respectively.

Here is the C++ program:

#include <iostream>

using namespace std;

int main()

{

int n;

string even_odd[2] = {“Even”, “Odd”};

cin>>n;

cout<<even_odd[n%2];

return 0;

}