1.

Write a function to sort the characters of the string passed to it as argument

Answer»

A C function to sort the characters of the string:

main()

{

char a[100],ch; int i,j;

printf ("\nEnter the string:-> ");

gets(a);

for (i=0;a[i]!='\0';i++)

{

for (j=i+1

a[j]!='\0';j++)

{

if (a[i]>a[j])

{

ch=a[i];

a[i]=a[j];

a[j]=ch;

}

}

}

printf ("\nString after sorting\n");

puts(a);

getch();



Discussion

No Comment Found

Related InterviewSolutions