Skip to content

Commit

Permalink
solve odd or even problem in cpp using AND bitwise operator
Browse files Browse the repository at this point in the history
  • Loading branch information
justanindieguy committed Jan 18, 2023
1 parent 4aae894 commit 9017e4a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Bit-manipulationTechniques/OddEven/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>

using namespace std;

int main()
{
int x;
cin >> x;

/* x & 1 will find out the last bit
* if last bit is 1 "x & 1" will return ...0001
* if last bit is 0 "x & 1" will return ...0000
*/
if (x & 1)
cout << "Odd" << endl;
else
cout << "Even" << endl;

return 0;
}

0 comments on commit 9017e4a

Please sign in to comment.