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
How the c program is executed?
What is bin sh c?
Explain what are the different data types in c?
What is strcmp in c?
What does %c do in c?
When is the “void” keyword used in a function?
What’s a signal? Explain what do I use signals for?
how can I convert a string to a number?
What is the use of getchar() function?
What would be an example of a structure analogous to structure c?
What are the advantages of c preprocessor?
How do c compilers work?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What are header files? What are their uses?
What is oops c?