C Program to Sort the Names or words in an Alphabetical Order 


#include <stdio.h>
#include <string.h>
 int main()
{
    char name1[10][8], name2[10][8], temp[8];
    int i, j, n;

    printf("Enter the number of names or words\n");
    scanf("%d", &n);
    printf("Enter %d names or words\n",n );
    for (i = 0; i < n; i++)
    {
        scanf("%s", name1[i]);
        printf("\n");
        strcpy(name2[i], name1[i]);
    }
    for (i = 0; i < n - 1 ; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (strcmp(name1[i], name1[j]) > 0)
            {
                strcpy(temp, name1[i]);
                strcpy(name1[i], name1[j]);
                strcpy(name1[j], temp);
            }
        }
    }
    printf("Input Names \t Sorted names\n\n");
    for (i = 0; i < n; i++)
    {
        printf("%s\t\t%s\n", name2[i], name1[i]);
    }
    return 0;
}