10

Possible Duplicate:
Is there a convenient function in objective-c / coca-touch to find a lowest number?

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int a=10,b=5,c;
    c=min(a,b);
    NSLog(@"min:%d",c);

    [pool drain];
    return 0;
}

I have to calculate the minimum value of two numbers. We can use if(a>b) to find out the minimum value.But is there any predefined function to calculate the minimum of two numbers.

Community
  • 1
  • 1
spandana
  • 755
  • 1
  • 13
  • 29
  • http://stackoverflow.com/questions/2125126/how-would-you-define-a-simple-min-method-in-obj-c exact duplicate – Kevin Jun 07 '11 at 11:24
  • Also take a look at http://stackoverflow.com/questions/844990/ and read the answer about `math.h`. – rid Jun 07 '11 at 11:26

1 Answers1

22

There was already a discussion about this here. Objective-C includes a MIN(a,b) macro, which should suit your needs.

Community
  • 1
  • 1
goetz
  • 916
  • 6
  • 14