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
Which is the best website to learn c programming?
What are the application of void data type in c?
What is pointer to pointer in c with example?
Write a program that accept anumber in words
What is the best organizational structure?
Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
Explain what is a program flowchart and explain how does it help in writing a program?
What is formal argument?
Explain About fork()?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
What are the features of the c language?
What is a nested loop?
c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above
In C programming, how do you insert quote characters (‘ and “) into the output screen?