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


Please Help Members By Posting Answers For Below Questions

What is scanf () in c?

665


A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

650


What is a floating point in c?

606


What are the advantages of using new operator as compared to the function malloc ()?

759


Why is python slower than c?

608






the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

1907


What is the difference between %d and %i?

597


What is #include in c?

601


What is a structure and why it is used?

622


What is 2 d array in c?

559


What is volatile keyword in c?

585


What do you mean by a local block?

632


What are the three constants used in c?

547


Explain what is the general form of a c program?

625


in iso what are the common technological language?

1638