The MSB bit of a number defines their sign. If the MSB bit is set, the number will be negative.
#include <stdio.h>
int main()
{
int sign = 0;
int data = 0;
printf("Enter the number\n");
scanf("%d",&data); //Get the number
sign = (data > 0) - (data < 0); // check the sign of the number
if(sign == 1)
{
printf("Enter number is a positve number\n");
}
else if(sign == -1)
{
printf("Enter number is a negative number\n");
}
else
{
printf("Enter number is zero\n");
}
return 0;
}
Answer:
The MSB bit of a number defines their sign. If the MSB bit is set, the number will be negative.
need an explanation for this answer? contact us directly to get an explanation for this answer