/*
============================================================================
Name : bubble_sort.c
Author : duanqibo
Version :
Copyright : Your copyright notice
Description : 输入6个成绩,冒泡排序,求平均分,再找出大于平均分的分数,最后将成绩中的偶数显示出来
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
//实现排序
void sort(int s[],int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
}
int main(void) {
int i;
int score[6];
setbuf(stdout,NULL);
printf("请输入6个成绩:");
for(i=0;i<6;i++) //循环输入6个成绩
{
scanf("%d",&score[i]);
}
//排序
sort(score,6);
printf("\n排序结果:\n");
for(i=0;i<6;i++) //循环输入6个成绩
{
printf("%3d",score[i]);
}
//查找偶数
printf("\n成绩中的偶数是:\n");
for(i=0;i<6;i++)
{
if(score[i]%2==0)
printf("%3d",score[i]);
}
//找出大于平均分的分数
int sum=0,avg=0;
for(i=0;i<6;i++)
{
sum=sum+score[i];
}
avg=sum/6;
printf("\n平均分:\n");
printf("%d",avg);
printf("\n大于平均分的分数有:\n");
for(i=0;i<6;i++)
{
if(score[i]>avg)
printf("%3d",score[i]);
}
return 1;
}