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 a null pointer assignment error? What are bus errors, memory faults, and core dumps?

1448


What is graph in c?

1063


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

1072


What is || operator and how does it function in a program?

1100


Write a code to remove duplicates in a string.

1046


Can you please explain the difference between syntax vs logical error?

1199


What is the purpose of the preprocessor directive error?

1277


What is methods in c?

1104


What is c system32 taskhostw exe?

1032


What is chain pointer in c?

1067


What is array of structure in c?

1189


How can I make it pause before closing the program output window?

1045


can we change the default calling convention in c if yes than how.........?

2541


Why does notstrcat(string, "!");Work?

1155


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2784