-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solve odd or even problem in cpp using AND bitwise operator
- Loading branch information
1 parent
4aae894
commit 9017e4a
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |