【C语言程序设计第四版】例10-6代码

#include <stdio.h>

int max(int a[], int m, int n){
    int k, u ,v;
    if (m ==n) {
        return a[m];
    }
    k = (m+n)/2;
    u = max(a, m ,k);
    v = max(a, k+1, n);
    
    return (u>v) ? u: v;
}

int min(int a[], int m, int n){
    int k, u ,v;
    if (m ==n) {
        return a[m];
    }
    k = (m+n)/2;
    u = min(a, m ,k);
    v = min(a, k+1, n);
    
    return (u<v) ? u: v;
}


int main(void){
    int a[10] = {3,4,1,9,7,5,4,3,2,1};
    
    int max_num, min_num;
    
    max_num = max(a, 0, 9);
    min_num = min(a, 0, 9);
    
    printf("max_num = %d, min_num = %d\n", max_num, min_num);
    
}

 

posted @ 2021-09-21 14:52  就是想学习  阅读(53)  评论(0编辑  收藏  举报