How to print 0 if input is even and 1 if input is odd without using control statements?
Solution:
#include<stdio.h>
#include<conio.h>
Int main()
{
Int num;
Printf("Enter any number:ā);
Scanf("%dā,&num);
Printf("result = %dā,1&num);
getch();
}
Explanation:
How this code work?
For this you should know about & operator. This is
binary AND operator. And there is an common fact about even number i.e. every
even number has 0 at the end in binary form and every odd number has 1 at the
end in binary form.
|