# Write a program to sort set of strings in ascending and descending order of their ... char
# Ascending
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main ()
{
int n , i ,j ;
char name[100] , temp;
scanf("%s", name);
n = strlen(name);
for (i=0 ; i<n ; i++)
{
for(j=i+1 ; j<n ;j++)
{
if(name[i] > name[j])
{
temp = name[i] ;
name[i] = name[j] ;
name[j] = temp;
}
}
}
printf("\n%s" , name);
getch() ;
return 0 ;
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Descending
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main ()
{
int n , i ,j ;
char name[100] , temp;
scanf("%s", name);
n = strlen(name);
for (i=0 ; i<n ; i++)
{
for(j=i+1 ; j<n ;j++)
{
if(name[i] < name[j])
{
temp = name[i] ;
name[i] = name[j] ;
name[j] = temp;
}
}
}
printf("\n%s" , name);
getch() ;
return 0 ;
}
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
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