#include <stdio.h>
void test( int * a, int len ,int *min, int * max, float *avg,int *sum)
{
for( int i =0; i < len ;i++){
if( a[i] > *max){
*max = a[i];
}else if( a[i] < *min ){
*min = a [i];
}
*sum += a[i];
}
*avg=*sum * 1.0f/len;
}
int main( int argc, const char * argv[]) {
int arr[] = { 12 , 34 , 54 , 65 , 78 , 98 , 1 , 2 };
int len = sizeof(arr) / sizeof(int);
int minArr = INT32_MAX;
int* minA = &minArr;
int maxArr = INT32_MIN;
int* maxA =&maxArr;
float avgArr;
float* avgA = &avgArr;
int sumArr = 0;
int* sumA = &sumArr;
test(arr,len,minA,maxA,avgA,sumA );
printf("数组最大值为:%d\n",maxArr);
printf("数组最小值为:%d\n",minArr);
printf("数组平均值为:%.2f\n",avgArr);
printf("数组累加和:%d\n",sumArr);
return 0;
} |
|