-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.c
More file actions
94 lines (76 loc) · 2.05 KB
/
Copy pathtempCodeRunnerFile.c
File metadata and controls
94 lines (76 loc) · 2.05 KB
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
// develop two arrays to store name,age sort them as per ascending age
// Sort them as per ascending name
// if more than 2 elements having same name ,then sort as per their age
// Sahil 10
// Sahil 20
// Likewise irrespective their actual position in an array
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 200
void main()
{
char name[50][50] , a[50];
int age[30],i,j,num , temp;
printf(" Enter no . person :-");
scanf("%d",&num);
printf("Enter %d persons NAME & AGE :-\n",num);
for(i=0;i<=num-1;i++)
{
printf("Enter person %d s name :-\n",i);
scanf("%s",&name[i]);
printf("Enter person %d s Age :-\n",i);
scanf("%d",&age[i]);
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(a,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],a);
// swap = name[i];
// name[i]= name[j];
// name[j]=swap;
temp = age[i];
age[i ]= age[j];
age[j] = temp;
}
}
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(strcmp(name[i],name[j])==0 && age[i]>age[i+1])
{
strcpy(a,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],a);
// swap = name[i];
// name[i]= name[j];
// name[j]=swap;
temp = age[i];
age[i ]= age[j];
age[j] = temp;
}
}
printf("Sorted List in ascending order :\n");
for(i=0;i<num;i++)
{
printf("\t%s",name[i]);
// printf("=====\n");
printf("\t%d \n",age[i]);
}
printf("-------\n");
// printf("Sorted List in ascending order :\n");
// for(i=0;i<num;i++)
// {
// printf("\t%s",name[i]);
// // printf("=====\n");
// printf("\t%d \n",age[i]);
// }
}
}