#include <stdio.h>
int sum(int score[],int N)
{
int sum1=0;
int i;
for(i=0;i<N;i++)
{
sum1+=score[i];
}
return sum1;
}
int getmax(int score[],int N)
{
int max=score[0];
int i;
for(i=1;i<N;i++)
{
if(score[i]>max)
max=score[i];
}
return max;
}
int getmin(int score[],int N)
{
int min=score[0];
int i;
for(i=1;i<N;i++)
{
if(score[i]<min)
min=score[i];
}
return min;
}
float getaver(int sum,int N)
{
float sum2=(float)(sum);
float aver=sum2/N;
return aver;
}
int paixu(int score[],int N)
{
int i,j,k;
for(i=N-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(score[j]<score[j+1])
{
int temp;
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
for(k=0;i<N;k++)
{
printf("%d\n",score[k]);
}
return 0;
}
int main()
{
int score[]={67,98,75,63,82,79,81,91,66,84};
int N=10;
int sum1=sum(score,N);
int max=getmax(score,N);
int min=getmin(score,N);
int aver=getaver(sum1,N);
printf("数组的和是%d\n",sum1);
printf("数组的最大值是%d\n",max);
printf("数组的最小值是%d\n",min);
printf("数组的平均值是%d\n",aver);
int paixu(score,N);
return 0;
}
运行结果:
数组的和是786
数组的最大值是98
数组的最小值是63
数组的平均值是78