T
Tomorrows
Unregistered / Unconfirmed
GUEST, unregistred user!
#include <stdio.h>
#define N 3
struct table {
char *name;
int math;
int phy;
int eng;
int total;
};
typedef struct table Table;
void Input(Table []);
void Output(Table []);
void Sort(Table []);
main()
{
Table student[N];
Input(student);
Sort(student);
Output(student);
return 0;
}
void Input(Table student[])
{
int i;
for(i=0;i<N;i++)
{
scanf("%s", student.name);
scanf("%d", &student.math);
scanf("%d", &student.phy);
scanf("%d", &student.eng);
student.total=student.math+student.phy+student.eng;
}
}
void Output(Table student[])
{
int i;
printf("Name/tMath/tPhysics/tEnglish/tTotal/n");
for(i=0;i<N;i++)
{
printf("%s", student.name);
printf("/t");
printf("%d", student.math);
printf("/t");
printf("%d", student.phy);
printf("/t");
printf("%d", student.eng);
printf("/t");
printf("%d", student.total);
printf("/n");
}
}
void Sort(Table student[])
{
int i, pass;
Table temp;
for(pass=1;pass<=N-1;pass++)
for(i=0;i<=N-2;i++)
if (student.total<student[i+1].total)
{
temp=student;
student=student[i+1];
student[i+1]=temp;
}
}
谢谢各位了
#define N 3
struct table {
char *name;
int math;
int phy;
int eng;
int total;
};
typedef struct table Table;
void Input(Table []);
void Output(Table []);
void Sort(Table []);
main()
{
Table student[N];
Input(student);
Sort(student);
Output(student);
return 0;
}
void Input(Table student[])
{
int i;
for(i=0;i<N;i++)
{
scanf("%s", student.name);
scanf("%d", &student.math);
scanf("%d", &student.phy);
scanf("%d", &student.eng);
student.total=student.math+student.phy+student.eng;
}
}
void Output(Table student[])
{
int i;
printf("Name/tMath/tPhysics/tEnglish/tTotal/n");
for(i=0;i<N;i++)
{
printf("%s", student.name);
printf("/t");
printf("%d", student.math);
printf("/t");
printf("%d", student.phy);
printf("/t");
printf("%d", student.eng);
printf("/t");
printf("%d", student.total);
printf("/n");
}
}
void Sort(Table student[])
{
int i, pass;
Table temp;
for(pass=1;pass<=N-1;pass++)
for(i=0;i<=N-2;i++)
if (student.total<student[i+1].total)
{
temp=student;
student=student[i+1];
student[i+1]=temp;
}
}
谢谢各位了