最小

2011-06-07 19 views
6

可能重複預定義功能:
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; 
} 

我需要計算兩個數的最小值。 我們可以用if(a> b)來找出最小值。但是有沒有任何預定義的函數來計算兩個數字的最小值。

+0

http://stackoverflow.com/questions/2125126/how-would-you-define-a-simple-min-method-in-obj-c精確重複 – Kevin 2011-06-07 11:24:05

+0

另請參見http:// stackoverflow。 com/questions/844990 /並閱讀關於'math.h'的答案。 – rid 2011-06-07 11:26:47

回答

17

已經有關於這個here的討論。 Objective-C包含一個MIN(a,b)宏,它應該滿足您的需求。