Advertisement
rafid_shad

sort many string in alplabetic order

Dec 4th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6.  
  7.     char str[5][20], t[20];
  8.     int i, j;
  9.     cout<<"Enter any five string (name) : \n";
  10.     for(i=0; i<5; i++)
  11.     {
  12.         cin>>str[i];
  13.     }
  14.     for(i=1; i<5; i++)
  15.     {
  16.         for(j=1; j<5; j++)
  17.         {
  18.             if(strcmp(str[j-1], str[j])==1)
  19.             {
  20.                 strcpy(t, str[j-1]);
  21.                 strcpy(str[j-1], str[j]);
  22.                 strcpy(str[j], t);
  23.             }
  24.         }
  25.         cout<<endl;
  26.        
  27.     }
  28.     cout<<endl<<"Strings (Names) in alphabetical order : \n";
  29.     for(i=0; i<5; i++)
  30.     {
  31.  
  32.         cout<<str[i]<<"\n";
  33.  
  34.     }
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement