#include <stdio.h> //找出一维数组中最大最小的数 int max(int *array, int len); //原型声明 int min(int *array, int len); //原型声明 int main() { int a[] = {1, 2, 4, 7, 10, 15, 17, 20, 100, 90, -1, 1000, 20001, -9, -199}; int len = sizeof(a) / sizeof(a[0]); printf("max=%d ", max(a, len)); printf("min=%d ", min(a, len)); return 0; } int max(int *array, int len) //或者int max(int array[], int len) { int max = array[0]; //先假设最大值是array[0] for (int i=0; i<len; i++) { if (max < array[i]) max = array[i]; } return max; } int min(int *array, int len) { int min = array[0]; //先假设最小值是array[0] for (int i=0; i<len; i++) { if (min > array[i]) min = array[i]; } return min; }