Saturday, 7 June 2014
This is tricky question which you can solve without need of relational operator. This type of question may be asked in interview not so important. Just apply the logic behind the questions correctly. You can do this question in your own way. Please let me know if u have other idea. Let see how I do it.
// find smallest or largest no without using comparison operators
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter value of A\n");
scanf("%d",&a);
printf("Enter value of B\n");
scanf("%d",&b);
printf("Enter value of C\n");
scanf("%d",&c);
if(a-b>0)
{
if(a-c>0)
{
printf("a is largest");
}
}
else if(b-c>0)
{
if(b-a>0)
{
printf("b is largest");
}
}
else
{
printf("c is largest");
}
}
// find smallest or largest no without using comparison operators
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter value of A\n");
scanf("%d",&a);
printf("Enter value of B\n");
scanf("%d",&b);
printf("Enter value of C\n");
scanf("%d",&c);
if(a-b>0)
{
if(a-c>0)
{
printf("a is largest");
}
}
else if(b-c>0)
{
if(b-a>0)
{
printf("b is largest");
}
}
else
{
printf("c is largest");
}
}