现场发挥的,没调试过,自己调试吧,有问题再说[
]
#include <stdio.h>
#include <math.h>
#define MAX_STUD 10
typedef struct _Student
{
char Name[20];
int Id;
char Sex[2];
float Math;
float English;
float Sum;
}Student;
void main()
{
Student StudInfo[MAX_STUD];
int MathPassCnt = 0,EnglishPassCnt = 0;
float MathPassRat,EnglisgPassRat;
int RealStudCnt = 0;
int i,j;
//Input Student
printf("Input student count/n");
scanf("%d/n",&RealStudCnt);
if (RealStudCnt <= 0)
{
printf("Input error/n");
return;
}
printf("Input student info(id,name,sex,math,english),one line is one student info/n");
for (i = 0;i < RealStudCnt;i ++)
{
scanf("%d,%s,%s,%f,%f/n",&StudInfo
.Id,StudInfo.Name,&StudInfo.Math,&StudInfo.English);
//you can check input value in here;
}
//sum
for (i = 0;i < RealStudCnt;i ++)
{
StudInfo.Sum = StudInfo.Math + StudInfo.English;
if (StudInfo.Math >= 60)
{
MathPassCnt ++;
}
if (StudInfo.English >= 60)
{
EnglishPassCnt ++;
}
}
MathPassRat = MathPassCnt / RealStudCnt;
EnglishPassRat = EnglishPassCnt / RealStudCnt;
//sort
Student Tmp;
for (i = 0;i < RealStudCnt;i ++)
{
for (j = 0,j < RealStudCnt - i;j ++)
{
if (StudInfo[j].Sum > StudInfo[j + 1].Sum)
{
Tmp = StudInfo[j];
StudInfo[j] = StudInfo[j + 1];
StudInfo[j + 1] = Tmp;
}
}
}
//out put
printf("Math PassCnt = %d,PassRat = %f/n",&MathPassCnt,&MathPassRat);
printf("English PassCnt = %d,PassRat = %f/n",&EnglishPassCnt,&EnglishPassRat);
printf("the student info is (order by sum)/n");
printf("/nID/tName/t/Sex/tMath/tEnglish/Sum/n");
for (i = 0;i < RealStudCnt;i ++)
{
printf("%d/t%s/t%s/t%f/t%f/t%f/n",&StudInfo.Id,StudInfo.Name,&StudInfo.Math,&StudInfo.English,&StudInfo.Sum);
}
return;
}