@DEBUGGING-GREATEST OF TWO INTEGERS

Go down

@DEBUGGING-GREATEST OF TWO INTEGERS

Post  prani on Tue Sep 09, 2008 2:07 pm

This question was asked in debugging elims...
Find the greatest of two integers without using relational operators..

prani

Posts : 15
Join date : 2008-08-12

View user profile

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  Admin on Wed Sep 10, 2008 4:52 am

dont worry all the problems in avishkar w'll b discussed but after avishkar .......
lets wait for some one 2 answer the question from 3rd years........

Admin
Admin

Posts : 39
Join date : 2008-08-03

View user profile http://computerclub09mnnit.forumotion.net

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  gumber on Wed Sep 10, 2008 8:44 am

(solution 1)-
Code:
int maxof2(int a,int b)
    {
        return (a + b + abs(a - b))/2;
    }

(solution 2)
Code:
inline int signof(int i)
{
    return unsigned(i) >> (sizeof (int) * 8 - 1);
}
 
int max(int a, int b)
{
    int p[2];
    p[0] = a;
    p[1] = b;
 
    return p[signof(a - b)];
}

gumber

Posts : 2
Join date : 2008-08-31

View user profile

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  rohit vashishtha on Thu Sep 18, 2008 5:45 am

int ta=a;
int tb=b;
while( ta && tb)
{
ta--;
tb--;
}
if(ta)
return a;
else
return b;
avatar
rohit vashishtha

Posts : 1
Join date : 2008-09-18

View user profile

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  satsung on Tue Sep 23, 2008 2:00 pm

int a,b;
if(a/b)
return a;
else
return b;

satsung

Posts : 2
Join date : 2008-08-10

View user profile

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  chunks on Thu Sep 25, 2008 5:47 am

The above solution will not work for one +ve and one -ve number
avatar
chunks

Posts : 6
Join date : 2008-08-14

View user profile

Back to top Go down

Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum