-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_sort_aname.c
43 lines (37 loc) · 970 Bytes
/
struct_sort_aname.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
#include <stdio.h>
#include <string.h>
typedef struct{
char name[30];
int roll;
float marks;
}okay;
void main() {
int n,i,j;
printf("Enter number of students\n");
scanf("%d", &n);
okay student[n];
okay temp;
printf("Enter roll, name and marks of student \n ");
for (int i = 0; i < n; i++)
{
scanf("%d", &student[i].roll);
scanf("%s", student[i].name);
scanf("%f", &student[i].marks);
}
for(i=0; i<(n-1); i++){
for(j=0; j<(n-1-i);j++){
if (strcmp(student[j].name, student[j + 1].name) > 0){
temp = student[j];
student[j] = student[j + 1];
student[j + 1] = temp;
}
}
}
printf("\nSorted data in ascending is : \n\n");
for(i=0;i<n;i++){
printf("%d ...............\n", i+1);
printf("Name of %d is %s\n",i+1,student[i].name);
printf("Roll = %d\n", student[i].roll);
printf("Marks = %.2f\n", student[i].marks);
}
}