Answer:
using namespace std;
// function to print string in sorted order
void sortString(string &str)
{
sort(str.begin(), str.end());
cout << str;
}
// Driver program to test above function
int main()
{
string s = "pleaseordertheaccounts";
sortString(s);
return 0;
}
Step-by-step explanation:
It can also work like:
using namespace std;
int main()
{
char str[5][20], t[20];
int i, j;
cout<<"\\ Enter Any Five Names : \\\\";
for(i=0; i<5; i++)
{
cout<<" ";
cin>>str[i];
}
for(i=1; i<5; i++)
{
for(j=1; j<5; j++)
{
if(strcmp(str[j-1], str[j])>0)
{
strcpy(t, str[j-1]);
strcpy(str[j-1], str[j]);
strcpy(str[j], t);
}
}
}
cout<<"\\ Names Sorted in Alphabetical Order : \\\\";
for(i=0; i<5; i++)
{
cout<<" ";
cout<<str[i]<<"\\";
}
return 0;
}