fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main() {
  4. char str[5][50], temp[50];
  5. printf("Enter 5 words: ");
  6. for(int i = 0; i < 5; ++i) {
  7. fgets(str[i], sizeof(str[i]), stdin);
  8. }
  9. for(int i = 0; i < 5; ++i) {
  10. for(int j = i+1; j < 5 ; ++j) {
  11. if(strcmp(str[i], str[j]) > 0) {
  12. strcpy(temp, str[i]);
  13. strcpy(str[i], str[j]);
  14. strcpy(str[j], temp);
  15. }
  16. }
  17. }
  18. printf("\nIn the lexicographical order: \n");
  19. for(int i = 0; i < 5; ++i) {
  20. fputs(str[i], stdout);
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
Enter 5 words: 
In the lexicographical order: 
0'���