C Program to arrange a string alphabetically
Program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
char ch, input[100], output[100];
int no[26] = {0}, n, i, j, x;
printf("Enter a string\n");
scanf("%s", input);
for (i = 0; i < strlen(input); i++)
{
ch = input[i] - 'a';
no[ch]++;
}
j = 0;
for (ch = 'a'; ch <= 'z'; ch++)
{
x = ch - 'a';
for (i = 0; i < no[x]; i++)
{
output[j] = ch;
j++;
}
}
output[j] = '\0';
printf("%s\n", output);
}
Output
Enter some text
kanyakumari
aaaikkmnruy