#include <stdio.h>
int zongfen(int score[])
{
int sum;
int i;
for(i=0;i<10;i++)
{
sum += score[i];
}
return sum;
}
int zgf(int score[])
{
int i;
int up=0;
for(i=0;i<10;i++)
{
if(score[i]>up)
{
up=score[i];
}
}
return up;
}
int zdf(int score[])
{
int i;
int down=100;
for(i=0;i<10;i++)
{
if(score[i]<down)
{
down = score[i];
}
}
return down;
}
void Dd(int score[])
{
int i,j;
for(i=8;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(score[j]>score[j+1])
{
int a;
a = score[j];
score[j]=score[j+1];
score[j+1]=a;
}
}
}
}
int main()
{
int score[10]={67,98,75,63,82,79,81,91,66,84};
int sum = zongfen(score);
printf("考试总分是:%d\n",sum);
int up = zgf(score);
printf("考试最高分是:%d\n",up);
int down = zdf(score);
printf("考试最低分是:%d\n",down);
float Ag = sum/10;
printf("考试平均分是:%f\n",Ag);//这里为什么是.000000而不是.600000?
printf("考试成绩降序:");
Dd(score);
int i;
for(i=9;i>=0;i--)
{
if(i!=0)
{
printf("%d,",score[i]);
}
else
printf("%d",score[i]);
}
return 0;
}
float Ag = (float)sum/10;在计算之前先强制转换一下sum的类型
平均值最后取值78.00000为什么不是78.600000?
直接代入总分函数算的话为什么取值是79.000000?