#include <stdio.h>
#define N 10
int Sum(int score[])
{
int i;
int sum;
for(i=0;i<N;i++)
{
sum=sum+score[i];
}
return sum;
}
int Max(int score[])
{
int max=-1;
int i;
for(i=0;i<N;i++)
{
if(score[i]>max)
{
max=score[i];
}
}
return max;
}
int Min(int score[])
{
int min=100;
int i;
for(i=0;i<N;i++)
{
if(score[i]<min)
{
min=score[i];
}
}
return min;
}
float Ave(int score[])
{
return Sum(score)/N;
}
int Rank(int score[])
{
int i,j;
int temp;
for(i=9;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(score[j]<score[j+1])
{
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
Rank(score);
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int sum=Sum(score);
int max=Max(score);
int min=Min(score);
float ave=Ave(score);
int rank=Rank(score);
printf("%d\n",sum);
printf("%d\n",max);
printf("%d\n",min);
printf("%f\n",ave);
printf("%d\n",rank);
return 0;
}
降序排序再加个循环输出就行了
我自己写采用了5分钟,改你的就用了半小时...
#include <stdio.h>
int Sum(int score[],int s[])
{
int i;
int sum=0;
for(i=0;i<10;i++)
{
sum+=score[i];
}
s[0]=sum;
return s[0];
}
int Max(int score[],int s[])
{
int a=-1;
int i;
for(i=0;i<10;i++)
{
if(score[i]>a)
{
a=score[i];
}
}
s[1]=a;
return s[1];
}
int Min(int score[],int s[])
{
int b=100;
int i;
for(i=0;i<10;i++)
{
if(score[i]<b)
{
b=score[i];
}
}
s[2]=b;
return s[2];
}
int Rank(int score[])
{
int i,j;
int temp;
for(i=9;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(score[j]<score[j+1])
{
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
return 0;
}
int main()
{
int sum,a,b,ave,d;
int score[10]={67,98,75,63,82,79,81,91,66,84};
int s[5]={1,2,3,4,5};
Sum(score,s);
printf("%d\n",s[0]);
Max(score,s);
Min(score,s);
Rank(score);
printf("%d\n",s[1]);
printf("%d\n",s[2]);
printf("%.1f\n",s[0]/10.0);
return 0;
}