December 06, 2022, 09:38:33 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Min() and Max() functions

Started by pistol350, July 06, 2007, 05:59:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pistol350

These functions take 2 arguments and return the argument with the smallest (minimum)  or the largest (maximum) value
They are very simple to use and can also be very helpful. :)
There are similar functions that support more than 2 arguments, so this may be the next step to reach. :)


"minmax.inc"

declare Min(int imin, int jmin),int;
declare Max(int imax, int jmax),int;

/* min function definition */
Sub Min(int imin, int jmin),int
{
    if (imin<jmin)
{
return imin;
}
    else
{
return jmin;
}
}



/* max function definition */
Sub Max(int imax, int jmax),int
{
    if (imax<jmax)
{
return jmax;
}
    else
{
return imax;
}
}


here is an example code

#include "minmax.inc"

global sub  main()
{
    int i = Min(5,8);
    int j = Max(5,8);

   print(" min : ",i);
   print(" min : ",j);
   print("press any key to close");
   While GetKey() = "";
   return 0;
}


I hope it can be helpful!
regards.
Peter
Regards,

Peter B.

sapero

Hey, he have already __min and __max in windef.inc (include windows.inc:)

BTW, the 'else' is not neccesary in this case, just 'return jmin' will be fine.

pistol350

LOL!
I was sure it was somewhere in the include files you added but i did not managed to find it. :D
Thanks!
Regards,

Peter B.