#include "stdio.h"
#include "string.h"
#define st 100
#define cr 5
struct date
{
int num;
char name[20];
int sc[cr];
}DATE[st];
int main()
{
int i, j,k, total_st[st], total_cr,temp;
double cr_average[cr], st_average[st];
char name[20],t_name[20];
for (i = 0; i < st; i++)
{
printf("Input number:");
scanf_s("%d", &DATE[i].num);
printf("Input name:");
scanf_s("%s", DATE[i].name, 20);
printf("Input the scores of the %d courses\n", cr);
for (j = 0; j < cr; j++)
{
printf("course%d:", (j + 1));
scanf_s("%d", &DATE[i].sc[j]);
}
}
for (i = 0; i < st; i++)
{
total_st[i] = DATE[i].sc[0];
for(j=1;j<cr;j++)
total_st[i]+= DATE[i].sc[j];
}
for (i = 0; i < st; i++)
{
total_st[i] = DATE[i].sc[0];
for (j = 1; j < cr; j++)
{
total_st[i] = total_st[i] + DATE[i].sc[j];
}
st_average[i] = (double)total_st[i] / (double)cr;
printf("The average of student%d:%f\n", (i + 1), st_average[i]);
}
for (i = 0; i < cr; i++)
{
total_cr = DATE[0].sc[i];
for (j = 1; j < st; j++)
{
total_cr += DATE[j].sc[i];
}
cr_average[i] = (double)total_cr / (double)st;
printf("The average of course%d:%f\n", (i + 1), cr_average[i]);
}
printf("Input the name you want find for:");
scanf_s("%s", name, 20);
for (i = 0; i < st; i++)
{
if (strcmp(DATE[i].name, name) == 0)
{
for (j = 0; j < cr; j++)
printf("Course%d:%d\n", (j + 1), DATE[i].sc[j]);
}
}
for(i=0;i<(st-1);i++)
for (j = 0; j < (st - i-1); j++)
if (total_st[j] < total_st[j + 1])
{
temp = total_st[j];
total_st[j] = total_st[j + 1];
total_st[j + 1] = temp;
temp = DATE[j].num;
DATE[j].num = DATE[j + 1].num;
DATE[j + 1].num = temp;
strcpy_s(t_name, DATE[j].name);
strcpy_s(DATE[j].name, DATE[j+1].name);
strcpy_s(DATE[j + 1].name, t_name);
for (k = 0; k < cr; k++)
{
temp = DATE[j].sc[k];
DATE[j].sc[k] = DATE[j + 1].sc[k];
DATE[j + 1].sc[k] = temp;
}
}
for (i = 0; i < st; i++)
{
printf("%d %s\n", DATE[i].num,DATE[i].name);
for (j = 0; j < cr; j++)
printf("Course%d:%d\n",(j + 1), DATE[i].sc[j]);
printf("\n");
}
}