#include <stdio.h>
#define N 30
void main()
{
int xuehao[N],chengji[N],a,i,t1,t2;
float ave,sum=0;
printf ("请输入学生总数\n");
scanf ("%d",&a);
printf("请输入学号和成绩\n");
for (i=0;i<a;i++)
{
scanf ("%d %d",&xuehao[i],&chengji[i]);
}
for (i=0;i<a;i++)
{
sum=sum+chengji[i];
}
ave=sum/a;
printf ("总分为:%.2f 平均成绩为:%.2f\n",sum,ave);
int c,d;
{
for (c=0;c<a;c++)
for(int d=0;d<a-c-1;d++)
{
if(xuehao[d]>xuehao[d+1])
{
t2=xuehao[d];
xuehao[d]=xuehao[d+1];
xuehao[d+1]=t2;
t1=chengji[d];
chengji[d]=chengji[d+1];
chengji[d+1]=t1;
}
}
}
printf ("按照学号由小到大\n");
for (c=0;c<a;c++)
printf ("%d\t%d\n",xuehao[c],chengji[c]);
{
for (i=0;i<a;i++)
for(int j=0;j<a-i-1;j++)
{
if(chengji[j]<chengji[j+1])
{
t1=chengji[j];
chengji[j]=chengji[j+1];
chengji[j+1]=t1;
t2=xuehao[j];
xuehao[j]=xuehao[j+1];
xuehao[j+1]=t2;
}
}
}
printf("按照成绩由高到低:\n");
for (i=0;i<a;i++)
printf ("%d\t%d\n",xuehao[i],chengji[i]);
int x;
printf ("请输入查询的学号\n");
scanf ("%d",&x);
for (i=0;i<a;i++)
{
if (xuehao[i]==x)
printf ("学号:%d 排名:%d 成绩%d\n",xuehao[i],(i+1),chengji[i]);
}
int y=0,l=0,j=0,b=0;
for (i=0;i<a;i++)
{
if (chengji[i]>=90&&chengji[i]<=100)
y++;
if (chengji[i]>=70&&chengji[i]<=89)
l++;
if (chengji[i]>=60&&chengji[i]<=69)
j++;
if (chengji[i]>=0&&chengji[i]<=59)
b++;
}
printf ("优秀\t良好\t及格\t不及格\t\n");
printf ("%d\t%d\t%d\t%d\t\n",y,l,j,b);
printf ("%.2f%%\t%.2f%%\t%.2f%%\t%.2f%%\t\n",(float)(100*y/a),(float)(100*l/a),(float)(100*j/a),(float)(100*b/a));
printf ("学号\t成绩\t\n");
for (i=0;i<a;i++)
{
printf("%d\t%d\n",xuehao[i],chengji[i]);
}
printf ("总分:%.2f\t平均分%.2f\t",sum,ave);
}
第九堂实验_1
最新推荐文章于 2021-07-25 04:06:17 发布