ADD file via upload

main
p72fupixj 1 year ago
parent cb7a1af61e
commit 7eaf94007d

53
4.c

@ -0,0 +1,53 @@
#include<stdio.h>
#define N 3
struct stu_info
{
int num,cls,flag;
float math,physics,english,total;
};
struct stu_info stu[N+1]={{10001,11,0,99.5,88.5,89.5,277.5},
{10002,12,0,77.9,56.5,87.5,221.9},
{10003,11,0,92.5,99.0,60.5,252},{}};
void sort(struct stu_info *stu,int n)
{
int i,j;
struct stu_info tmp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(((stu+j)->cls>(stu+j+1)->cls)||((stu+j)->cls==(stu+j+1)->cls)&&((stu+j)->total<(stu+j+1)->total))
{
tmp = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = tmp;
}
}
}
return;
}
int main()
{
scanf("%d",&stu[N].num);
scanf("%d",&stu[N].cls);
scanf("%f",&stu[N].math);
scanf("%f",&stu[N].physics);
scanf("%f",&stu[N].english);
stu[N].flag=1;
stu[N].total=stu[N].math+stu[N].physics+stu[N].english;
int check=1,i,n=N+1;
for(i=0;i<N;i++) if(stu[i].num==stu[N].num) check=0;
if(!check) n--;
sort(stu,n);
for(i=0;i<n;i++)
{
printf("%d %d %.1f %.1f %.1f",stu[i].num,stu[i].cls,stu[i].math,stu[i].physics,stu[i].english);
if(stu[i].flag) printf(" inserted");
printf("\n");
}
return 0;
}
Loading…
Cancel
Save