#define N 10
#include <stdio.h>
int all(int score[])//总和
{
int sum = 0;
for (int i = 0; i < N; i++)
{
sum += score[i];
}
return sum;
}
int max(int score[])//最大值
{
int temp = 0;
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < 10 - i; k++)
{
if (score[i] < score[k])
{
temp = score[i];
score[i] = score[k];
score[k] = temp;
}
}
}
int max;
max=score[9];
return max;
}
int min(int score[])//最小值
{
int temp = 0;
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < 10 - i; k++)
{
if (score[i] < score[k])
{
temp = score[i];
score[i] = score[k];
score[k] = temp;
}
}
}
int min = score[0];
return min;
}
int ping(int all)//平均数
{
int ping = all / N;
return ping;
}
void jian(int score[])//降低排序
{
int temp = 0;
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < 10 - i; k++)
{
if (score[i] > score[k])
{
temp = score[i];
score[i] = score[k];
score[k] = temp;
}
}
}
for (int i = 0; i < N; i++)
{
printf("%d\n", score[i]);
}
}
int main()//主函数
{
int score[N] = { 67,98,75,63,82,79,81,91,66,84 };
int all = all( score);
int max = max( score);
int min = min( score);
int average = ping(all);
jian(0);
return 0;
}
#include <stdio.h>
#define N 10
int main()
{
int score[N]={67,98,75,63,82,79,81,91,66,84};
int i,j;
int Max=0,Min=score[0],temp;
float Mid=0,Sum=0;
for(i=0;i<N;i++)Sum+=score[i]; //总成绩
Mid=Sum/N;//平均分
for(i=0;i<N;i++)
{
if(score[i]>Max)Max=score[i]; //最高
if(score[i]<Min)Min=score[i]; //最低
}
for(i=N-1-1;i>=0;i--)//冒泡排序N-下标-1
{
for(j=0;j<=i;j++)//前一个与后一个比较,直到最后
{
if(score[j]<score[j+1])//前一个小于后一个则进行交换
{
temp=score[j];
score[j]=score[j+1];
score[j+1]=temp;
}
}
}
printf("总分:%.1f分\n最高分:%d分\n最低分:%d分\n平均分:%.1f分\n",Sum,Max,Min,Mid);
printf("冒泡法降序排序:");
for(i=0;i<N;i++)
printf("%d ",score[i]);
return 0;
}
void jian(int score[])//降低排序
{
int temp = 0;
for (int i = 0; i < 10; i++)
{
for (int k = 0; k < 9; k++)
{
if (score[k] < score[k+1])
{
temp = score[k+1];
score[k+1] = score[k];
score[k] = temp;
}
}
}
反了 降序应该把大的放前面