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 a null pointer assignment error? What are bus errors, memory faults, and core dumps?
What is graph in c?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
What is || operator and how does it function in a program?
Write a code to remove duplicates in a string.
Can you please explain the difference between syntax vs logical error?
What is the purpose of the preprocessor directive error?
What is methods in c?
What is c system32 taskhostw exe?
What is chain pointer in c?
What is array of structure in c?
How can I make it pause before closing the program output window?
can we change the default calling convention in c if yes than how.........?
Why does notstrcat(string, "!");Work?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion