int max(int a,int b)
{
int g=0 ;
!a && b && ( ((b+1)/b ) && (g = b) || (g=a));
!b && a && ( ((a+1)/a ) && (g = a) || (g=b));
(!(!a || !b)) &&
( (( ( !((b+1)/b) && (!( a/b) ) )
|| ( ((a+1)/a) && (a/b) )
) && (g=a))
|| (g=b)
);
return g;
}
logic is here:
int max(int a,int b)
{
int g=0 ;
if (a == 0 and b != 0 ) {
if ( b is +ve)
b is greatest
else
a is greatest
}
if (b == 0 and a != 0 ) {
if ( a is +ve)
a is greatest
else
b is greatest
}
if ( a and b are non-zero ) {
if( [b is negative and b is magnitudely high]
or [a is positive and a is magnitudely high] )
then
a is greatest
otherwise
b is greatest
}
return the greatest value;
}
NOTE: this program will not work for a single value LONG_MAX;
Unit-test and other ideas are added as comments
Subscribe to Post Comments [Atom]
July 2005 August 2005 October 2005 December 2005 March 2006 June 2006 July 2006 December 2006 February 2007 June 2007 March 2010 May 2010
Subscribe to Posts [Atom]