write a program to compare 2 numbers without using logical
operators?

Answer Posted / faceless

main()
{
int result, sign_bit_num;
unsigned int x, y;

sign_bit_num = sizeof(int)*8 ;

result = x-y;

if (result) {
result = result >> (sign_bit_num-1);

if (result) {
printf("x less than y");
} else {
printf("x greater than y");
}
} else {
printf("equal");
}

Is This Answer Correct ?    14 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate call by value and call by reference?

776


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

868


What is a macro?

905


What is unsigned int in c?

770


number of times a digit is present in a number

1818


Write a program of prime number using recursion.

861


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

883


What is the use of a semicolon (;) at the end of every program statement?

1180


Are there any problems with performing mathematical operations on different variable types?

835


Explain about C function prototype?

865


What are the complete rules for header file searching?

886


What is class and object in c?

845


What is the use of extern in c?

874


What is header file definition?

866


What is the purpose of realloc()?

913