Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 30: Write a C++ program to arrange into ascending order.

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
	string str;
	cout<<"\nenter a string : ";
	cin>>str;
	int size=str.length();

	for(int i=0;i<size-1;i++)
	{
		char min=str[i],temp;
		int pos=i;
		for(int j=i+1;j<size;j++)
		{
			if(min>str[j])
			{
				min=str[j];
				pos=j;
			}
		}
		temp=str[i];
		str[i]=str[pos];
		str[pos]=temp;
	}
	cout<<"\nstring in ascending order : "<<str;
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.