Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include #include int main() { int i, j; char str[10][50], temp[50]; printf(\"En

ID: 3833155 • Letter: #

Question

#include

#include

int main()

{

    int i, j;

    char str[10][50], temp[50];

    printf("Enter 10 words: ");

    for(i=0; i<10; ++i)

        scanf("%s[^ ]",str[i]);

    for(i=0; i<9; ++i)

        for(j=i+1; j<10 ; ++j)

        {

            if(strcmp(str[i], str[j])>0)

            {

                strcpy(temp, str[i]);

                strcpy(str[i], str[j]);

                strcpy(str[j], temp);

            }

        }

    printf(" In lexicographical order: ");

    for(i=0; i<10; ++i)

    {

        puts(str[i]);

    }

    return 0;

}

What does this code do? (Describe)

Explanation / Answer

main.c

/*this program gives lexicographical order of 10 words entered by user.

lexicographic order is increasing numerical order or alphabetic order for words.*/

#include<stdio.h>
#include<string.h>
int main()
{
    int i, j;
    char str[10][50], temp[50];
    printf("Enter 10 words: ");
    for(i=0; i<10; ++i)
        scanf("%s[^ ]",str[i]);
    for(i=0; i<9; ++i)
        for(j=i+1; j<10 ; ++j)
        {
            if(strcmp(str[i], str[j])>0)
            {
                strcpy(temp, str[i]);
                strcpy(str[i], str[j]);
                strcpy(str[j], temp);
            }
        }
    printf(" In lexicographical order: ");
    for(i=0; i<10; ++i)
    {
        puts(str[i]);
    }
    return 0;
}

Output :-