-
Notifications
You must be signed in to change notification settings - Fork 16
/
15.c
65 lines (59 loc) · 1.42 KB
/
15.c
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
#include <stdio.h>
// Define the date structure
struct date
{
int day;
int month;
int year;
};
// Define the student_record structure
struct student_record
{
char name[50];
struct date dob;
int totalMarks;
};
int main()
{
struct student_record students[] = {
{
.name = "John Doe",
.dob = {1, 1, 2000},
.totalMarks = 90,
},
{
.name = "Jane Doe",
.dob = {2, 2, 2000},
.totalMarks = 80,
},
{
.name = "Peter Smith",
.dob = {3, 3, 2000},
.totalMarks = 70,
},
};
// Sort the students rank-wise based on total marks
for (int i = 0; i < 3; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (students[i].totalMarks < students[j].totalMarks)
{
struct student_record temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
// Display the students rank-wise
printf("\nStudents Rank-wise:\n");
for (int i = 0; i < 3; i++)
{
printf("Rank %d\n", i + 1);
printf("Name: %s\n", students[i].name);
printf("Date of Birth: %d-%d-%d\n", students[i].dob.day, students[i].dob.month, students[i].dob.year);
printf("Total Marks: %d\n", students[i].totalMarks);
printf("\n");
}
return 0;
}