c语言中求数组的最小值和最大值

 

#include <stdio.h>

int main(void)
{
    int a[7] = {45,32,86,56,24,98,85};
    int min, max;
    min = a[0]; max = a[0];    
    int i;
    for (i = 0; i < 7; i ++)
    {
        if (a[i] < min)
            min = a[i];
        if (a[i] > max)
            max = a[i];
    }
    printf("min = %d\n", min);
    printf("max = %d\n", max);
    return 0;
}

 

posted @ 2021-01-09 12:55  小鲨鱼2018  阅读(6520)  评论(0编辑  收藏  举报