向上爬的鱼
2016-03-06 13:59
#include <stdio.h>
#define N 10
int scoreSum(int score[])
{
int i;
int sum = 0;
for(i=0;i<N;i++)
{
sum += score[i];
}
return sum;
}
int scoreMax(int score[])
{
int i,max;
for(i=0;i<N;i++)
{
max = score[0];
if(score[i]>max)
max = score[i];
}
return max;
}
int scoreMin(int score[])
{
int i,min;
for(i=0;i<N;i++)
{
min = score[0];
if(score[i]<min)
min = score[i];
}
return min;
}
int scoreAvg(int score[])
{
int i;
int sum = 0;
int avg = 0;
for(i=0;i<N;i++)
{
sum += score[i];
}
avg = sum/N;
return avg;
}
int bubbleSort(int score[])
{
int i,j;
int temp=0;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(score[j]<score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
for(i=0;i<10;i++)
{
printf("%d ",score[i]);
}
return 0;
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int sum,avg,max,min;
sum = scoreSum(score);
avg = scoreAvg(score);
max = scoreMax(score);
min = scoreMin(score);
printf("总分是:%d\n",sum);
printf("平均分是:%d\n",avg);
printf("最高分是:%d\n",max);
printf("最低分是:%d\n",min);
bubbleSort(score);
return 0;
}
score[j]<score[j+1];当j=9,时没有定义score[10],而且最大最小输出不对。
#include <stdio.h>
#define N 10
int scoreSum(int score[])
{
int i;
int sum = 0;
for(i=0;i<N;i++)
{
sum += score[i];
}
return sum;
}
int scoreMax(int score[])
{
int i,max;
max = score[0];
for(i=0;i<N;i++)
{
if(score[i]>max)
max = score[i];
}
return max;
}
int scoreMin(int score[])
{
int i,min;
min = score[0];
for(i=0;i<N;i++)
{
if(score[i]<min)
min = score[i];
}
return min;
}
int scoreAvg(int score[])
{
int i;
int sum = 0;
int avg = 0;
for(i=0;i<N;i++)
{
sum += score[i];
}
avg = sum/N;
return avg;
}
int bubbleSort(int score[])
{
int i,j;
int temp=0;
for(j=0;j<N-1;j++)
{
if(score[j]<score[j+1])
{
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
for(i=0;i<10;i++)
{
printf("%d ",score[i]);
}
return 0;
}
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int sum,avg,max,min;
sum = scoreSum(score);
avg = scoreAvg(score);
max = scoreMax(score);
min = scoreMin(score);
printf("总分是:%d\n",sum);
printf("平均分是:%d\n",avg);
printf("最高分是:%d\n",max);
printf("最低分是:%d\n",min);
bubbleSort(score);
return 0;
}
C语言入门
926210 学习 · 20797 问题
相似问题
回答 3
回答 1