@DEBUGGING-GREATEST OF TWO INTEGERS
+2
Admin
prani
6 posters
Page 1 of 1
@DEBUGGING-GREATEST OF TWO INTEGERS
This question was asked in debugging elims...
Find the greatest of two integers without using relational operators..
Find the greatest of two integers without using relational operators..
prani- Posts : 15
Join date : 2008-08-12
Re: @DEBUGGING-GREATEST OF TWO INTEGERS
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........
lets wait for some one 2 answer the question from 3rd years........
Re: @DEBUGGING-GREATEST OF TWO INTEGERS
(solution 1)-
(solution 2)
- 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
Re: @DEBUGGING-GREATEST OF TWO INTEGERS
int ta=a;
int tb=b;
while( ta && tb)
{
ta--;
tb--;
}
if(ta)
return a;
else
return b;
int tb=b;
while( ta && tb)
{
ta--;
tb--;
}
if(ta)
return a;
else
return b;
rohit vashishtha- Posts : 1
Join date : 2008-09-18
Re: @DEBUGGING-GREATEST OF TWO INTEGERS
int a,b;
if(a/b)
return a;
else
return b;
if(a/b)
return a;
else
return b;
satsung- Posts : 2
Join date : 2008-08-10
Re: @DEBUGGING-GREATEST OF TWO INTEGERS
The above solution will not work for one +ve and one -ve number
chunks- Posts : 6
Join date : 2008-08-14
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum