1,105,226 Community Members

greatest of three nos

Member Avatar
kbkorlahalli
Newbie Poster
1 post since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Salem
Posting Sage
7,177 posts since Dec 2005
Reputation Points: 5,138 [?]
Q&As Helped to Solve: 970 [?]
Skill Endorsements: 41 [?]
Team Colleague
 
0
 

Is this on your college course?

Member Avatar
jephthah
Posting Maven
2,572 posts since Feb 2008
Reputation Points: 1,888 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 5 [?]
 
1
 

i see nothing much has changed since ive been gone.

Member Avatar
paragt
Newbie Poster
3 posts since Aug 2008
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 
/*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.

Member Avatar
Salem
Posting Sage
7,177 posts since Dec 2005
Reputation Points: 5,138 [?]
Q&As Helped to Solve: 970 [?]
Skill Endorsements: 41 [?]
Team Colleague
 
1
 

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

Perhaps, who cares.

You didn't ANSWER THE QUESTION.
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.

Member Avatar
hiraksarkardg
Light Poster
27 posts since Sep 2008
Reputation Points: -5 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

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
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article