Rule:-
In this method first we find the integer division of the by 2 and multiply by 2 in to the result if we got the number then number is even otherwise number is odd number
Ex:-
Take number is 5
step 1:- find integer division by 2 i.e. 5//2=2
step 2:- again multiply by 2 in the result i.e. 2*2=4
since 4 is not equal to the given number so it is a odd number
2)
Take number is 6
step 1:- find integer division by 2 i.e. 6//2=3
step 2:- multiply by 2 in the result i.e. 3*2=6
since 6 is equal to the given number so it is a even number
Program:-
n=int(input("number="))
int_div=n//2
mul=int_div*2
if mul==n:
print("Even number")
else:
print("Odd number")
output:-
number=6
Even number
0 Comments