Check if a Number is Odd or Even using Bitwise Operators
C++
// C++ program to check for even or odd
// using Bitwise AND operator
#include <iostream>
using namespace std;
// Returns true if n is even, else odd
bool isEven(int n)
{
// n&1 is 1, then odd, else even
return (!(n & 1));
}
// Driver code
int main()
{
int n = 101;
isEven(n)
? cout << "Even"
: cout << "Odd";
return 0;
}
// C++ program to check for even or odd
// using Bitwise XOR operator
#include <iostream>
using namespace std;
// Returns true if n is even, else odd
bool isEven(int n)
{
// n^1 is n+1, then even, else odd
if (n ^ 1 == n + 1)
return true;
else
return false;
}
// Driver code
int main()
{
int n = 100;
isEven(n)
? cout << "Even"
: cout << "Odd";
return 0;
}
Also in C++:
- Title
- count number of zeros in array in O(logN)
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- gta san andreas
- Category
- C++
- Title
- range of long long in c++
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- hobo 8
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- c++ create object
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- c++ movment
- Category
- C++
- Title
- coronavirus
- Category
- C++
- Title
- cout value c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- how to use max_element in c++ with vector
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- vector concat c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- opencv compile c++
- Category
- C++
- Title
- counting valleys hackerrank solution in c++
- Category
- C++
- Title
- initialize array c++
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- how to put a class in a .h file c++
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- initialize map c++
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- c++ formatting
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- c++ read file line by line
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- c++ course
- Category
- C++
- Title
- chess perft 5
- Category
- C++
- Title
- setbits
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- templates of templates c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- can you use rand to read in from an external file inc++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- ternary search c++
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- matrix multiplication c++ eigen
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- c++ multidimensional vector
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- set in c++
- Category
- C++