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
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 |
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 |
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 |
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 |
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 |
What is console in c language?
Write a program that accepts a string where multiple spaces are given in between the words. Print the string ignoring the multiple spaces. Example: Input: “ We.....Are....Student “ Note: one .=1 Space Output: "We Are Student"
Is there any possibility to create customized header file with c programming language?
how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--);
How variables are declared in c?
What header files do I need in order to define the standard library functions I use?
What is the usage of the pointer in c?
int main() { int x = (2,3,4); int y = 9,10,11; printf("%d %d",x,y); } what would be the output?
write a program to display numbers from 1 to 10 and 10 to 1?
The C language terminator is a.semicolon b.colon c.period d.exclamation mark
if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.
Why doesn't the code "a[i] = i++;" work?