PTA 用指针寻找数组中的最大值和最小值

#include 

void minmax(int a[], int len, int *min, int *max);

int main(void)
{
    int a[] = {1,2,3,4,5,6,7,8,9,12,13,14,16,17,21,23,0};
    int min, max;

    minmax(a, sizeof(a)/sizeof(a[0]), &min, &max);

    printf("min=%d, max=%d\n", min, max);

    return 0;
}

void minmax(int a[], int len, int *min, int *max)
{
    int i;

    *min = *max = a[0];
    for(i=1; i *max)
        {
            *max = a[i];
        }
    }
}

 

你可能感兴趣的:(C/C++)