+ 2
How to get the odd and even numbers?
Please
6 Respostas
+ 1
x&1
this will check the least significant bit, lab. if it's 1 means odd, else even
0
if (x % 2 == 0) {
std::cout << "it's Odd./n";
}
if (x % 2 != 0) {
std::cout << "it's Even./n";
}
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
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()
}
- 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;
}
- 2
also
if (x % 2 = 1)
cout << "It's Even";