Advertisement
ppupil2

Q6-PRF192-PE-trial

Mar 23rd, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6.  
  7. int main() {
  8.   system("cls");
  9.   //INPUT - @STUDENT:ADD YOUR CODE FOR INPUT HERE:
  10.     char a[5][30];
  11.    
  12.     for (int i = 0; i<5; i++) {
  13.         fflush(stdin);
  14.         scanf("%[^\n]", &a[i]);
  15.     }
  16.  
  17.     int i, j;
  18.     char temp[30];
  19.  
  20.     for (i = 5 - 1; i > 0; i--) {
  21.         for (j = 0; j < i; j++) {
  22.             if (strcmp(a[j], a[j+1]) > 0) {
  23.                 strcpy(temp, a[j]);
  24.                 strcpy(a[j], a[j+1]);
  25.                 strcpy(a[j+1], temp);
  26.             }
  27.         }
  28.     }
  29.  
  30.  
  31.  
  32.  
  33.   // Fixed Do not edit anything here.
  34.   printf("\nOUTPUT:\n");
  35.   //@STUDENT: WRITE YOUR OUTPUT HERE:
  36.  
  37.     printf("%s", a[0]);
  38.     for(int i = 1; i<5; i++) printf(" %s", a[i]);
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.   //--FIXED PART - DO NOT EDIT ANY THINGS HERE
  49.   printf("\n");
  50.   system ("pause");
  51.   return(0);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement