In: Computer Science
write a program to perform the following in C
If you have any doubts, please give me comment...
#include <stdio.h>
#include <string.h>
int main()
{
const int n = 10;
char words[n][50], temp[50];
int i, j;
printf("Enter 10 words:\n");
for (i = 0; i < n; i++)
scanf("%s", words[i]);
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (strcmp(words[i], words[j]) > 0)
{
strcpy(temp, words[i]);
strcpy(words[i], words[j]);
strcpy(words[j], temp);
}
}
}
printf("\nAfter sorting strings in alphabetical order is:\n");
for(i=0; i<n; i++){
printf("%s\n", words[i]);
}
return 0;
}
Let me know, if you are facing any errors. Thank you...