xxxxxxxxxx
if ( n % 2 == 0 ) {
// n is even
}
else {
//otherwise odd
}
xxxxxxxxxx
// @Author: Subodh
// 1 liner solution
(num & 1) ? cout << num << " is odd" : cout << num << " is even" << endl;
xxxxxxxxxx
#check wheather a is odd or even
'''interactive mode
>>> 10%2
0. .False #(False==0)
>>> 5%2
1. .True #(True==1)'''
#scriptive mode
a=int(input('enter:'))
if a%2:
print("its odd")#solution gives true if 'a' value is even
else:
print("its even")#solution gives false if 'a' value is odd
print('hope it helped')
#output
#False
enter:100
its even
hope it helped
#even
enter:101
its odd
hope it helped
xxxxxxxxxx
#include<iostream>
using namespace std;
int main() {
int num;
cout<<"enter a number /n";
cin>> num ;
if(num % 2 == 0){
cout<<num<<" is an even number"<<endl;
}
else{
cout<<num<<" is an odd number"<<endl;
}
return 0;
}