How to get the odd and even numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to get the odd and even numbers?

Please

9th Jul 2016, 3:28 AM
Paul John
6 Answers
+ 1
x&1 this will check the least significant bit, lab. if it's 1 means odd, else even
9th Jul 2016, 9:20 AM
Tareque Md Khan
Tareque Md Khan - avatar
0
if (x % 2 == 0) { std::cout << "it's Odd./n"; } if (x % 2 != 0) { std::cout << "it's Even./n"; }
9th Jul 2016, 3:34 AM
Yann Amaral
Yann Amaral - avatar
0
You can also use bitwise operators. int i; while(cin >> i) if(i & 1) cout << "odd" << endl; else cout << "even" << endl; cout << "done" << endl
9th Jul 2016, 5:42 AM
Tony Christopher
Tony Christopher - avatar
0
#include<iostream.h> #include<conio.h> void main() { int a; cout<<"Enter the number "; con>>a; if(a%2==0) cout<<"Number is even"; else cout<<"number is odd"; getch() }
18th Jul 2016, 5:09 PM
Vishu Smart
Vishu Smart - avatar
- 1
#include <iostream> using namespace std; int main() { int x ; cin>>x; if (x % 2 == 0) { cout << "it's Even "; } else if (x % 2 != 0) { cout << "it's odd"; } return 0; }
10th Jul 2016, 3:42 AM
Razan Shalabi
Razan Shalabi - avatar
- 2
also if (x % 2 = 1) cout << "It's Even";
9th Jul 2016, 5:02 AM
Paul John