In: Computer Science
Write c code to determine if a binary number is even or odd. If it is odd, it outputs 1, and if it is even, it outputs 0. It has to be less than 12 operations. The operations have to be logical, bitwise, and arithmetic.
Code:
#include<stdio.h>
int main()
{
int bin;
/*Here we declared a integer*/
printf("Enter a binary number: ");
scanf("%d",&bin);
/*Here we read the binary number from the user*/
if(bin%10==1)
{
printf("%d",1);
}
if(bin%10==0)
{
printf("%d",0);
}
/*
if the last bit is 1 then it is odd
if the last bit is 0 then it is even*/
}
Output:
Indentation: