Write a C program to find the smallest of three integers,
without using any of the comparision operators.
Answer Posted / jb
The trick is to use the sign bit
void main() {
int a = 1;
int b = 2;
int c = 3;
int maximum = max(max(a,b),c);
}
int max(int a, int b) {
int diff = a - b;
int sign = (diff >> 31) & 0x1;
return a - (sign * diff);
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the code in while loop that returns the output of given code?
Why do we use c for the speed of light?
Tell me what is null pointer in c?
What are loops c?
Explain what are the __date__ and __time__ preprocessor commands?
regarding pointers concept
Write programs for String Reversal & Palindrome check
Does * p ++ increment p or what it points to?
What is a macro in c preprocessor?
What is strcpy() function?
how to write optimum code to divide a 50 digit number with a 25 digit number??
What is a #include preprocessor?
Is fortran still used today?
What is unary operator?
What is the difference between union and anonymous union?