include stdio include stdlib include string typedef struct student cha

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student
{
char name[10];
char group[10];
int marks[5];
};
void pprint (struct student A)
{
printf ("%s \t %s \t %d, %d, %d, %d, %d\n",A.name, A.group, A.marks[0], A.marks[1],A.marks[2],A.marks[3],A.marks[4]);
}
int compare(const void *_a, const void *_b)
{
struct student *a = (struct student *)_a;
struct student *b = (struct student *)_b;
double ma=0.0, mb=0.0;
for (int i=0;i<5;i++)
{
ma+=a->marks[i];
mb+=b->marks[i];
}
//Для доступа к членам структуры с помощью указателя на структуру следует использовать оператор "стрелка".
return ma-mb;
}
int main()
{
//struct student s[5];
struct student s[5]={{"Petrov","dddd-2",{1,2,3,2,3}},
{"Popov","dddd-2",{4,5,4,5,2}},
{"Smirnov","dddd-5",{5,2,5,5,3}},
{"Lupova","dddd-4",{1,2,3,2,4}},
{"Torko","dddd-3",{1,2,3,4,3}}};
/*int i = 0;
while (i<5)
{
scanf("%10s", &s[i].name);
scanf("%10s",&s[i].group);
for (int j=0;j<5;j++)
scanf("%d",&s[i].marks[j]);
i++;
}*/
for (int i=0;i<5;i++)
{
pprint (s[i]);
}
qsort(s, 5, sizeof(s[0]), compare);
printf("\n");
for (int i=0;i<5;i++)
{
pprint (s[i]);
}
return 0;
}