how to check if the number is even or odd using bitwise operator code example

Example 1: how to check if the number is even or odd using bitwise operator

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int num;
	cin>>num;
	if(num & 1){
		cout<<"odd";
	}
	else{
		cout<<"even";
	}
	return 0;
}

Example 2: how to check if the number is even or odd using bitwise operator

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int num;
	cin>>num;
	if(num & 1){
		cout<<"odd";
	}
	else{
		cout<<"even";
	}
	return 0;
}

Tags:

Cpp Example