Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 the code in while loop that returns the output of given code?

1983


Why do we use c for the speed of light?

1200


Tell me what is null pointer in c?

1072


What are loops c?

1052


Explain what are the __date__ and __time__ preprocessor commands?

1116


regarding pointers concept

2035


Write programs for String Reversal & Palindrome check

1057


Does * p ++ increment p or what it points to?

1117


What is a macro in c preprocessor?

1098


What is strcpy() function?

1139


how to write optimum code to divide a 50 digit number with a 25 digit number??

3267


What is a #include preprocessor?

1146


Is fortran still used today?

1089


What is unary operator?

1098


What is the difference between union and anonymous union?

1302