int main() {
int n;
cin>>n;
if(n & 1){
cout<<"Odd";
}
else{
cout<<"Even";
}
return 0 ;
}
Problem of the day
Write a program that uses bitwise AND operator to check if a given positive integer is even or odd.
A single Integer, N
Output Format:
Print "Odd” if N is odd otherwise "Even".
1<=N<=10^4
Interview problems
99.12 % better
int main() {
int n;
cin>>n;
if(n & 1){
cout<<"Odd";
}
else{
cout<<"Even";
}
return 0 ;
}
Interview problems
C++
#include<iostream>
using namespace std;
int main() {
// Write your code here
int n;
cin>>n;
if(n&1){
cout<<"Odd"<<endl;
}else{
cout<<"Even"<<endl;
}
}
Interview problems
C++
#include<iostream>
using namespace std;
int main() {
int num;
// Get input from the user
std::cin >> num;
// Use bitwise AND operator to check the least significant bit
// If the least significant bit is 0, the number is even; otherwise, it's odd
if (num & 1) {
std::cout << "Odd"<< std::endl;
} else {
std::cout << "Even" << std::endl;
}
return 0;
}