#include <stdio.h>
int all(int score)
{
printf("%d",score);
}
int high(score[])
{
int a;
int max=score[0];
for(a=1;a<10;a++)
{
if(score[a]>max)
max=score[a];
}
return max;
}
int low(score[])
{
int b;
int min=score[0];
for(b=1;b<10;b++)
{
if(score[b]<min)
min=score[b];
}
return min;
}
int paixu(score[])
{
int c,d;
for(c=9;c>=0;c--)
{
for(d=0;d<=c;d++)
{
if(score[d+1]<score[d])
{ int e;
e=score[d];
score[d]=score[d+1];
score[d+1]=e;
}
}
}
for(c=0;c<10,c++)
{
printf("%d",score[c])
}
}
int main()
{ int sum=0;
int score[10]={67,98,75,63,82,79,81,91,66,84};
int i;
for(i=0;i<10;i++)
{sum+=all(score[i]);}
printf("考试的总分为%d\n",sum);
printf("考试平均分为%d\n",sum/N);
printf("最高分为%d\n",high(score));
printf("最低分为%d\n",low(score));
printf("考试成绩降序排列为%d\n",paixu(score))
return 0;
}
函数声明错误、部分输出语句没有加;、排序那个外部循环初始值应为8,或者把内部循环改为< 、输出语句类型不对应,前面是%d整形的,后面是个调用一个函数。我也是新手,哪里说错忘见谅。我的代码:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int total(int score[])
{
int i;
int sum = 0;
for(i=0;i<10;i++)
{
sum +=score[i];
}
printf("考试的总分为:%d\n",sum);
return 0;
}
int max(int score[])
{
int i;
int max=0;
for(i=0;i<10;i++)
{
if(score[i]>max)
{
max = score[i];
}
}
printf("考试的最高分为:%d\n",max);
return 0;
}
int min(int score[])
{
int i;
int min;
for(i=0;i<10;i++)
{
if(score[i]<score[i+1])
{
min = score[i];
}
}
printf("考试的最低分为:%d\n",min);
return 0;
}
int average(int score[])
{
int i;
int sum = 0;
for(i=0;i<10;i++)
{
sum +=score[i];
}
int average = sum/10;
printf("考试的平均分为:%d\n",average);
return 0;
}
int sort(int score[])
{
int i,j;
printf("排序前\n");
for(i=0;i<10;i++)
{
if(i!=9)
{
printf("%d,",score[i]);
}else
{
printf("%d\n",score[i]);
}
}
for(i=9;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;
}
}
}
printf("排序后\n");
for(i=0;i<10;i++)
{
if(i!=9)
{
printf("%d,",score[i]);
}else
{
printf("%d\n",score[i]);
}
}
return 0;
}
int main(int argc, char *argv[]) {
int score[]={67,98,75,63,82,79,81,91,66,84};
total(score);
max(score);
min(score);
average(score);
sort(score);
return 0;
}