write a program to compare 2 numbers without using logical
operators?
Answer Posted / rishabh
#include<stdio.h>
#include<limits.h>
int sign(int number)
{
return (unsigned) number / (unsigned) INT_MIN;
}
int main(int argc, char *argv[])
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int dif = a - b;
int sb1 = sign(dif);
int sb2 = sign(dif - 1) - sb1;
int ptr = 2 * sb2 + sb1;
char *messages[3] =
{
"%d is greater than %d",
"%d is less than %d",
"%d is equal to %d" };
printf(messages[ptr], a, b);
}
}
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
What is the function of multilevel pointer in c?
Where is c used?
Explain the difference between malloc() and calloc() function?
Write a program to implement queue.
How many levels deep can include files be nested?
What are different types of operators?
What is static and volatile in c?
What are the header files used in c language?
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
What are the disadvantages of external storage class?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
Can a pointer be volatile in c?
What is a sequential access file?
When the macros gets expanded?
Difference between linking and loading?