1. 程式人生 > >c語言 找最小值

c語言 找最小值

main printf turn int style std 語言 %d include

#include <stdio.h>  
#define N 10  
#define MIN(X,Y) ((X<Y)?(X):(Y))  
    
int f(int arr[],int len,int n)  
{  
    if(n == len-1)  
        return arr[n];  
        
    int min = f(arr,len,n+1);  
    
    return MIN(min,arr[n]);  
}  
    
int main (void)  
{  
    int arr[N] = {2,4,1
,3,5,6,7,8,-11}; int min = f(arr,N,0); printf("%d ",min); return 0; }

c語言 找最小值