sorted characters in a string in c

Solutions on MaxInterview for sorted characters in a string in c by the best coders in the world

showing results for - "sorted characters in a string in c"
Flore
26 Nov 2017
1#include <stdio.h>
2
3void sorted_string(char s[]){
4	char temp;
5	int i,j,len=strlen(s);
6
7	for(i=0;i<len;i++){
8		for(j=0;j<len;j++){
9			if(s[i] < s[j]){
10				temp=s[i];
11				s[i]=s[j];
12				s[j]=temp;
13			}
14		}
15	}
16
17	//printf("string after sorting %s\n",s);
18}
19
20int main(){
21	char s[1001];
22    scanf(" %[^\n]", s);
23    printf("String before sorting : %s\n",s);
24    sorted_string(s);
25    printf("String after sorting : %s\n",s);
26	return 0;
27}
similar questions
queries leading to this page
sorted characters in a string in c