Computer Club MNNIT
Would you like to react to this message? Create an account in a few clicks or log in to continue.

@DEBUGGING-GREATEST OF TWO INTEGERS

+2
Admin
prani
6 posters

Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty @DEBUGGING-GREATEST OF TWO INTEGERS

Post  prani 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

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  Admin 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

https://computerclub09mnnit.forumotion.net

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  gumber 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

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  rohit vashishtha 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;
rohit vashishtha
rohit vashishtha

Posts : 1
Join date : 2008-09-18

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  satsung 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

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty Re: @DEBUGGING-GREATEST OF TWO INTEGERS

Post  chunks Thu Sep 25, 2008 5:47 am

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

Posts : 6
Join date : 2008-08-14

Back to top Go down

@DEBUGGING-GREATEST OF TWO INTEGERS Empty 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