Write a C program to find the smallest of three integers,
without using any of the comparision operators.

Answers were Sorted based on User's Feedback



Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / srinivas

#include <stdio.h>

int main(void)
{
int a = 10, b = 2, c = 30, result;

result = a < b ? ((a < c) ? a: c) : ((b < c) ? b : c);
printf("%d\n",result);
return 0;


}

Is This Answer Correct ?    9 Yes 3 No

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / niranjan

main()
{
int a=5,b=2,c=3; /*Assuming a Use Case */
int d; /* d is required a temporary variable */
if(!(a/b)&& !(a/c))
{
d = a; /* Which means a is small */
}
else if ( !(b/a)&&!(b/c))
{
d = b; /* Which means b is small */
}
else
{
d = c;
}

printf("%d",d);
}

Is This Answer Correct ?    7 Yes 3 No

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / dinesh

b is the smallest number of above three values

Is This Answer Correct ?    8 Yes 5 No

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / 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

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / eswaran

Sorry this is wrong answer....

Is This Answer Correct ?    3 Yes 5 No

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / n r sree harsha

#include<stdio.h>
#include<math.h> /* for using abs() function */
main()
{
int a,b,c,small;
printf("\n enter numbers");
scanf("%d%d%d",&a,&b,&c);
if(abs(a-b)-(a-b))
{
if(abs(a-c)-(a-c))
{
s=a;
else
s=c;
}
else
{
if(abs(b-c)-(b-c))
{
s=b;
else
s=c;
}
}
printf("\n small=%d",s);
}

Is This Answer Correct ?    0 Yes 2 No

Write a C program to find the smallest of three integers, without using any of the comparision oper..

Answer / sachin golechha

Try Doing this way::

main()
{
int a=10,b=7,c=13; /*Assuming a Use Case */
int d; /* d is required a temporary variable */
if((a-b))
{
d = b; /* Which means a was greater than b */
}
else
{
d = a; /* Which means b was greater than a */
}

if((d-c))
{
d = c; /* Which means d was greater than c */
}
else
{
d = d; /* Which means c was greater than d */
}
/* Thus d contains the smallest number of among the 3 */

return SUCCESS;
}

Is This Answer Correct ?    22 Yes 25 No

Post New Answer

More C Interview Questions

What is && in c programming?

0 Answers  


What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int);

3 Answers   Bosch,


What is string concatenation in c?

0 Answers  


What is array within structure?

0 Answers  


What do you mean by dynamic memory allocation in c? What functions are used?

0 Answers  


we compile c program in 32 processor and 64 bit processor .exe file is created in both the processors. if we want to run .exe file in 64 bit processor which is created in 32 bit processor. is that .exe file is run or not if it is not run why?

4 Answers   HP, Wipro,


which will be first in c compiling ,linking or compiling ,debugging.

3 Answers   Sonata,


write a program to print calender using for loop.

1 Answers   HCL, TCS,


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

0 Answers  


While(1) { } when this loop get terminate is it a infinite loop?

5 Answers  


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

0 Answers  


What is difference between structure and union in c programming?

0 Answers  


Categories