1.11M Members

hello friends
can u tell me how to find greatest of three nos using bitwise operators?

Is this on your college course?

i see nothing much has changed since ive been gone.

``````/*Program to find the greatest of three numbers*/
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
clrscr();
printf("Enter the three numbers");
scanf("%d%d%d",&x,&y,&z);

if(x>y)
{
if(y>z)
printf("Greatest number is %d",x);
else
if(z>x)
printf("Greatest number is %d",z);
}
else
{
if(x>z)
printf("Greatest number is %d",y);
else
if(z>y)
printf("Greatest number is %d",z);
}
return 0;
}``````

contact me at <<email snipped>> to let me know if the code worked.

contact me at nobody@nowhere-we-care-about.com to let me know if the code worked.

Perhaps, who cares.

Any muppet can do it using > and <, but the trick is, can you do it with &, | and ^ ?

Nor did you read the copious (some would say deluge) of information which tells you to use code-tags.

Here's my answer...no > or < operator used....

``````#include<stdio.h>
int greater(int,int);  //Returns 1 if former is greater tha latter, else 0.
main()
{
int a,b,c,flag,flag1;
printf("Enter the three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
flag=greater(a,b);
if(flag==1)
{
flag1=greater(a,c);
if(flag1==1)
printf("A biggest\n");
else
printf("C biggest\n");
}
else
{
flag1=greater(b,c);
if(flag1==1)
printf("B biggest\n");
else
printf("C biggest\n");
}
}

int greater(int x,int y)
{
int i,check,m,n,pos=31;
check=1;
check=check<<pos;
m=x&check;
n=y&check;
if((m!=0)&&(n==0))
return(0);
else if((m==0)&&(n!=0))
return(1);
else
{
check=1;
check=check<<30;
for(i=30;i>=0;i--)
{
pos--;
check=check>>1;
m=x&check;
n=y&check;
if((m!=0)&&(n==0))
return(1);
else if((m==0)&&(n!=0))
return(0);
}
}
}``````
You