排序你可以用最简单的冒泡或者选择排序,以平均分为标准
#include<stdio.h>
typedef struct student
{
int num
char name[20]
int Score1
int Score2
int Score3
float average
}student
student st[3]
void CreateStudent(student st[])
{
int i,j
float Average
for(i=0i<3i++)
{
printf("请输入学生%d的资料:\n",i+1)
printf("学号为:")
scanf("%d",&st[i].num)
printf("姓名是:")
scanf("%s",&st[i].name)
printf("第1门成绩是:")
scanf("%d",&st[i].Score1)
printf("第2门成绩是:")
scanf("%d",&st[i].Score2)
printf("第3门成绩是:")
scanf("%d",&st[i].Score3)
printf("\n"键芹)
st[i].average = (st[i].Score1+st[i].Score2+st[i].Score3)/3
}
}
void SortStudent(student st[],int 稿配毕nLength)
{
int i, j, max
student temp
for(i=0 i<nLengthi++)
{
max = i
for(j=i+1 j<nLength j++)
{
if(st[j].average > st[max].average)
max = j
}
if(max != i)
{
temp = st[i]
st[i] = st[max]
st[max] = temp
}
}
}
int main()
{
int j
CreateStudent(st)
SortStudent(st,3)
printf("学号\t姓名\t语文\t数学\t英卖消语\t平均分\n")
for(j=0j<3j++)
{
printf("%d",st[j].num)
printf("\t%s",st[j].name)
printf("\t%d",st[j].Score1)
printf("\t%d",st[j].Score2)
printf("\t%d",st[j].Score3)
printf("\t%2f",st[j].average)
printf("\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n")
}
}
#include<stdio.h>#define STNUM 3 //学改慧生数
struct student{
char id[10]
char name[10]
float course[3]
}
int main(){
student st[STNUM] //student结构体数组
int i,j
printf("==========录入信息==========\n")
for(i=0i<STNUMi++){
printf("请输入兆悄第%d个学生的信息\n",i+1)
printf("请输入学号:")
scanf("%10s",&st[i].id)
printf("请输入姓名:")
scanf("%10s",&st[i].name)
printf("请输入3门课的成绩:")
for(j=0j<3j++){
scanf("%f",&st[i].course[j])
sum[i] += st[i].course[j]
}
}
printf("==========学生信息==========\n")
for(i=0i<STNUMi++){
printf("-----------学生%d----------\n",i+1)
printf("学号:%s\n",st[i].id)
printf("姓名:%s\n",st[i].name)
printf("3门课的成绩:")
for(j=0j<3j++){
printf("%.1f ",st[i].course[j])
sum[i] 族歼渣+= st[i].course[j]
}
printf("\n")
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)