Answers for "sorted characters in a string in c"

C
0

sorted characters in a string in c

#include <stdio.h>

void sorted_string(char s[]){
	char temp;
	int i,j,len=strlen(s);

	for(i=0;i<len;i++){
		for(j=0;j<len;j++){
			if(s[i] < s[j]){
				temp=s[i];
				s[i]=s[j];
				s[j]=temp;
			}
		}
	}

	//printf("string after sorting %s\n",s);
}

int main(){
	char s[1001];
    scanf(" %[^\n]", s);
    printf("String before sorting : %s\n",s);
    sorted_string(s);
    printf("String after sorting : %s\n",s);
	return 0;
}
Posted by: Guest on September-27-2021

Code answers related to "sorted characters in a string in c"

Code answers related to "C"

Browse Popular Code Answers by Language