C Program To Sort The Words In Alphabetical Order | C Programming

C Program To Sort The Words In Alphabetical Order

#include <stdio.h>
#include <string.h>
int main()
{
    int i, j, n;
    char str[25][25], temp[25];
    puts("How many strings you are going to enter?: ");
    scanf("%d", &n);
    puts("Enter Strings one by one: ");
    for (i = 0; i <= n; i++)
    {
        gets(str[i]);
    }
    for (i = 0; i <= n; i++)
        for (j = i + 1; j <= n; j++)
        {
            if (strcmp(str[i], str[j]) > 0)
            {
                strcpy(temp, str[i]);
                strcpy(str[i], str[j]);
                strcpy(str[j], temp);
            }
        }
    printf("Order of Sorted Strings:");
    for (i = 0; i <= n; i++)
        puts(str[i]);
    return 0;
}

OUTPUT

C Program To Sort The Words In Alphabetical Order

Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming