-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct program
101 lines (78 loc) · 2.01 KB
/
struct program
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<conio.h>
#include<stdio.h>
struct PCM
{
int P;
int C;
int M;
};
struct Student
{
char Sname[30];
char Sid[10];
int total;
struct PCM sub;
};
void sort(int n,struct Student srec[20],struct Student temp[20])
{
int i,j;
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-i;j++)
{
if(srec[i].total<srec[i+1].total)
{
temp[i]=srec[i];
srec[i]=srec[i+1];
srec[i+1]=temp[i];
}
else if(srec[i].total==srec[i+1].total)
{
if(srec[i].sub.M>srec[i+1].sub.M)
{
temp[i]=srec[i];
srec[i]=srec[i+1];
srec[i+1]=temp[i];
}
else if(srec[i].sub.M==srec[i+1].sub.M)
{
if(srec[i].sub.P>srec[i+1].sub.P)
{
temp[i]=srec[i];
srec[i]=srec[i+1];
srec[i+1]=temp[i];
}
else if(srec[i].sub.P==srec[i+1].sub.P)
{
if(srec[i].sub.C>srec[i+1].sub.C)
{
temp[i]=srec[i];
srec[i]=srec[i+1];
srec[i+1]=temp[i];
}
}
}
}
}
}
}
void main()
{
struct Student srec[20];
struct Student temp[20];
struct PCM sub[20];
int n,i;
printf("enter total no of students");
scanf("%d",&n);
printf("enter student name,id,PCM marks respectively ");
for(i=1;i<=n;i++)
{
scanf("%s%s%d%d%d",srec[i].Sname,srec[i].Sid,&srec[i].sub.P,&srec[i].sub.C,&srec[i].sub.M);
srec[i].total=srec[i].sub.P+srec[i].sub.C+srec[i].sub.M;
}
sort(n,srec,temp);
for(i=1;i<=n;i++)
{
printf("\n %4s %4s %4d",srec[i].Sname,srec[i].Sid,srec[i].total);
}
}