ADD file via upload

main
psc4a9qur 1 week ago
parent 46a17d5f2d
commit 4b9a53f64a

96
a5.c

@ -0,0 +1,96 @@
#include <stdio.h>
#include <string.h>
struct stu {
char num[6];
int class;
char name[6];
float grade1;
float grade2;
float grade3;
float grade;
}s[10],ss;
int main()
{
strcpy(s[0].num,"10001");s[0].class=11;strcpy(s[0].name,"Zhang");s[0].grade1=99.5;s[0].grade2=88.5;s[0].grade3=89.5;s[0].grade=s[0].grade1+s[0].grade2+s[0].grade3;
strcpy(s[1].num,"10002");s[1].class=12;strcpy(s[1].name,"Yang");s[1].grade1=77.9;s[1].grade2=56.5;s[1].grade3=87.5;s[1].grade=s[1].grade1+s[1].grade2+s[1].grade3;
strcpy(s[2].num,"10003");s[2].class=11;strcpy(s[2].name,"Liang");s[2].grade1=92.5;s[2].grade2=99.0;s[2].grade3=60.5;s[2].grade=s[2].grade1+s[2].grade2+s[2].grade3;
char z[6];
scanf("%s",z);
int a=0,m;
for(int i=0;i<3;i++)
{
if(strcmp(z,s[i].name)==0||strcmp(z,s[i].num)==0)
{
m=i;
a=1;
break;
}
}
if(a==1)
{
if(m<=1)
{
for(int j=m;j<2;j++)
{
s[j]=s[j+1];
}
}
for(int i=0;i<1;i++)
{
ss=s[i];
for(int j=i+1;j<2;j++)
{
if(s[i].grade<s[j].grade)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
for(int i=0;i<2;i++)
{
printf("%s %d %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
}
}
else
{
for(int i=0;i<3;i++)
{
printf("%s %d %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
}
return 0;
}
printf("Are you sure(yes/no)?\n");
char x;
scanf("%c",&x);
scanf("%c",&x);
if(x=='n')
{
strcpy(s[0].num,"10001");s[0].class=11;strcpy(s[0].name,"Zhang");s[0].grade1=99.5;s[0].grade2=88.5;s[0].grade3=89.5;
strcpy(s[1].num,"10002");s[1].class=12;strcpy(s[1].name,"Yang");s[1].grade1=77.9;s[1].grade2=56.5;s[1].grade3=87.5;
strcpy(s[2].num,"10003");s[2].class=11;strcpy(s[2].name,"Liang");s[2].grade1=92.5;s[2].grade2=99.0;s[2].grade3=60.5;
for(int i=0;i<2;i++)
{
ss=s[i];
for(int j=i+1;j<3;j++)
{
if(s[i].grade<s[j].grade)
{
ss=s[i];
s[i]=s[j];
s[j]=ss;
}
}
}
for(int i=0;i<3;i++)
{
printf("%s %d %s %.1f %.1f %.1f\n",s[i].num,s[i].class,s[i].name,s[i].grade1,s[i].grade2,s[i].grade3);
}
}
else if(x=='y')
return 0;
return 0;
}
Loading…
Cancel
Save