#include
int max,min,sum=0;
void find(int a[],int n)
{
int i;
min=max=a[0];
for(i=0;i { if(min>a[i]) min=a[i];
#include
int max_num = 0;
int min_num = 0;
int ave_num = 0;
int FindMaxMinAve(int a[],int n)
{
int i;
int tmp_max = a[0];
int tmp_min = a[0];
int tmp_ave = 0;
int tmp_sum = 0;
for(i=1;i
if(a[i]>tmp_max)
{
tmp_max = a[i];
}
if(a[i]
tmp_min = a[i];
}
tmp_sum+=a[i];
}
tmp_ave = tmp_sum/n;
ave_num = tmp_ave;
min_num = tmp_min;
max_num = tmp_max;
return 0;
}
int main(void)
{
int i;
int a[20];
for(i=0;i<20;i++)
{
scanf("%d",&a[i]);
}
FindMaxMinAve(a,20);
printf("maxnum is %d\n",max_num);
printf("minnum is %d\n",min_num);
printf("avenum is %d\n",ave_num);
fflush(stdin);
getchar();
return 0;
}
#include
double max,min,ave;
void count_max(double a[]) //求最大值
{
int i;
max=a[0];
for(i=1;i<20;i++)
if(a[i]>max)
max=a[i];
}
void count_min(double a[]) //求最小值
{
int i;
min=a[0];
for(i=1;i<20;i++)
if(a[i]min=a[i];
}
void count_ave(double a[]) //求平均值
{
double sum=0;
int i;
for(i=0;i<20;i++)
sum+=a[i];
ave=sum/20;
}
int main()
{
double a[20];
int i;
for(i=0;i<20;i++) //数据输入
scanf("%lf",&a[i]);
count_max(a); //计算
count_min(a);
count_ave(a);
printf("最大值:%f\n",max); //输出
printf("最小值:%f\n",min);
printf("平均值:%f\n",ave);
return 0;
}
#include "stdio.h"
#include "stdlib.h"
#define NUM_COUNT 20
int g_max;
int g_min;
float g_avr;
int comp(const void * a, const void * b)
{
return *(int*)b - *(int*)a;
}
void main()
{
int a[NUM_COUNT];
int sum = 0;
for (int i = 0; i< NUM_COUNT; i++)
{
scanf("%d",a+i);
sum +=a[i];
}
g_avr = sum/NUM_COUNT;
qsort(a,NUM_COUNT,4,comp);
g_max = a[0];
g_min = a[NUM_COUNT - 1];
printf("平均数:%f \n最大数:%d \n最小数:%d\n", g_avr, g_max, g_min);
}