-
Notifications
You must be signed in to change notification settings - Fork 0
/
46John3.c
44 lines (36 loc) · 1.01 KB
/
46John3.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
/*
Roll no:46
Batch:B
Author Name:John Joy
Date:2/09/23
Description:ascending order based on roll no
*/
#include <stdio.h>
#include <string.h>
struct Student {
int roll_no;
char name[50];
float percentage;
};
int compare(const void *a, const void *b) {
return ((struct Student *)a)->roll_no - ((struct Student *)b)->roll_no;
}
int main() {
struct Student students[5];
for (int i = 0; i < 5; i++) {
printf("Enter details for student %d:\n", i + 1);
printf("Roll Number: ");
scanf("%d", &students[i].roll_no);
printf("Name: ");
scanf("%s", students[i].name);
printf("Percentage: ");
scanf("%f", &students[i].percentage);
}
qsort(students, 5, sizeof(struct Student), compare);
printf("\nStudent Records (Sorted by Roll Number):\n");
printf("Roll No\tName\tPercentage\n");
for (int i = 0; i < 5; i++) {
printf("%d\t%s\t%.2f\n", students[i].roll_no, students[i].name, students[i].percentage);
}
return 0;
}