有的时候能成功运行,有的时候会出现错误
有的时候运行会出现 segmentation fault的字样 然后就运行失败了
#include <stdio.h>
int sum(int score[])
{
int sum=0;
int i;
for (i=0;i<10;i++)
{
sum = sum + score[i];
}
return sum;
}
int max (int score[])
{
int max = 0;
int i;
for (i=0;i<9;i++)
{
if (score[i]>score[i+1])
{
max= score[i];
}
}
return max;
}
int low (int score[])
{
int low = 0;
int i;
for (i=0;i<9;i++)
{
if (score[i]<score[i+1])
{
low = score[i];
}
}
return low;
}
int average(int score[])
{
int sum=0;
for (int i=0;i<10;i++)
{
sum= sum+score[i];
}
return sum/10;
}
void order( int score[])
{
int i,j;
for (i=9;i>=0;i--)
{
for (j=0;j<=i;j++)
{
int temp = 0;
if (score[j]>score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
}
int main()
{
int score[10]={67,98,75,63,82,79,81,91,66,84};
printf("总分为%d\n",sum(score));
printf("最高分为%d\n",max(score));
printf("最低分为%d\n",low(score));
printf("平均分为%d\n",average(score));
order(score);
int i;
for (i=0;i<10;i++)
{
printf("%d\t",score[i]);
}
printf("\n");
return 0;
}