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
List some applications of c programming language?
How many types of operator or there in c?
what are non standard function in c
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
In c language can we compile a program without main() function?
What would be an example of a structure analogous to structure c?
What are the various types of control structures in programming?
In C programming, what command or code can be used to determine if a number of odd or even?
Explain the difference between #include "..." And #include <...> In c?
What is meant by keywords in c?
Is printf a keyword?
Is stack a keyword in c?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
What will be your course of action for a push operation?
What are the properties of union in c?