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 difference between functions abs() and fabs()?
What is a good way to implement complex numbers in c?
a program that can input number of records and can view it again the record
What are the scope of static variables?
Explain how can you avoid including a header more than once?
Can you please explain the difference between exit() and _exit() function?
What does dm mean sexually?
Which type of language is c?
Why do some versions of toupper act strangely if given an upper-case letter?
What is a built-in function in C?
What is I ++ in c programming?
What is output redirection?
What are the types of pointers in c?
How to establish connection with oracle database software from c language?
What is function prototype in c with example?