Hello Friends
well thanks to John(both of you) the second mail helped me shorten the 
code.(taking value of a by default, assuming it as the larger one.)
for the MIN MAX macros, i appreciate your suggestion as i did not know 
about them, but i didnt want to use the ternary operator, if-conditional 
or any loop. As the macro MIN and MAX uses ?: i would keep it aside for 
the time being
any other ideas for the same thing are welcome and would be appreciated. 
:-)

Thanks & Regards.

anup
On 12/26/2009 9:48 PM, John Gaughan wrote:
>
> On 12/26/2009 5:57 AM, Anup Joshi wrote:
> > Hello friends,
> > I wanted to find biggest number of given two numbers without using the
> > loop statement, the if-conditional, or the ternary operator ?:. One way
> > i could do this was with the following code:
> >
> > int biggest(int a, int b) {
> > int result;
> >
> > (a<b)&& (result = b); // b is bigger
> > (a>b)&& (result =a); // a is bigger
> > (a==b)&& (result = a) // both are equal
> >
> > return result;
> > }
> >
> > this code works for positive as well as negative ints.
> > i wanted to know if there was any other way to find the biggest number
> > of the two, by using any other c operator or snippet.
> >
>
> If you look in your standard headers (I think math.h or cmath) you will
> find macros called MIN and MAX. They typically use the ternary operator,
> and reduce your logic above to two paths. You can combine the second and
> third conditions into a single one. You could define an inline function
> like this:
>
> inline int max(int a, int b) {
> return a > b ? a : b;
> }
>
> If this is for C++ I would use a template function so it works with
> other data types.
>
> -- 
> John Gaughan
> http://www.jtgprogramming.org/ <http://www.jtgprogramming.org/>
>
> 



[Non-text portions of this message have been removed]

Reply via email to