去掉最高值,去掉最低值,求平均值 用c语言void Max(const int *arr,int len,int *max){} void Min(const int *arr,int len,int *min){} void Sum(const int *arr,int len,int *sum){} void Avg(int sum,int max,int min,int len,float *avg){} void test03(){ int arr[]={1,2,5,4,3,6,7}; int len =sizeof (arr)/sizeof (int); }
时间: 2023-08-28 07:08:58 浏览: 85
去掉一个最高分一个最低分,求平均值
5星 · 资源好评率100%
可以按照以下方式实现:
```c
#include <stdio.h>
void Max(const int *arr, int len, int *max)
{
*max = arr[0];
for(int i = 1; i < len; i++)
{
if(arr[i] > *max)
{
*max = arr[i];
}
}
}
void Min(const int *arr, int len, int *min)
{
*min = arr[0];
for(int i = 1; i < len; i++)
{
if(arr[i] < *min)
{
*min = arr[i];
}
}
}
void Sum(const int *arr, int len, int *sum)
{
*sum = 0;
for(int i = 0; i < len; i++)
{
*sum += arr[i];
}
}
void Avg(int sum, int max, int min, int len, float *avg)
{
*avg = (float)(sum - max - min) / (len - 2);
}
void test03()
{
int arr[] = {1, 2, 5, 4, 3, 6, 7};
int len = sizeof(arr) / sizeof(int);
int max, min, sum;
float avg;
Max(arr, len, &max);
Min(arr, len, &min);
Sum(arr, len, &sum);
Avg(sum, max, min, len, &avg);
printf("Max: %d\n", max);
printf("Min: %d\n", min);
printf("Sum: %d\n", sum);
printf("Avg: %.2f\n", avg);
}
int main()
{
test03();
return 0;
}
```
输出结果为:
```
Max: 7
Min: 2
Sum: 28
Avg: 3.50
```
阅读全文