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 g value paradox?
What is clrscr ()?
Explain what will the preprocessor do for a program?
What is external variable in c?
Explain what is the difference between far and near ?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
What is context in c?
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
How can I recover the file name given an open stream?
What is calloc malloc realloc in c?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What does the characters “r” and “w” mean when writing programs that will make use of files?
Is sizeof a keyword in c?
write a program for the normal snake games find in most of the mobiles.
what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values