/*array.c */ /*an array example */ /*Author: Weiwei Chen */ /*Date: Nov. 7. 2010 */ #include int findmax(int p[10]); int findmin(int p[10]); int main() { int i, max, min; int a[] = {1, 2, 3, 4, 5, 10, 9, 8, 7, 6}; /* display the content of the array */ for(i = 0; i < 10; i ++) { printf("a[%d] = %d \n", i, a[i]); } /* find the maximum and minimum value in the array*/ max = findmax(a); min = findmin(a); printf("the maximum value is: %d \n", max); printf("the minimum value is: %d \n", min); return 0; } int findmax(int p[10]) { int max = p[1]; int i; for(i = 0; i < 10; i ++) { if(max < p[i]) { max = p[i]; } } return max; } int findmin(int p[10]) { int min = p[1]; int i; for(i = 0; i < 10; i ++) { if(min > p[i]) { min = p[i]; } } return min; }