My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to sort a string

Tuesday, September 1, 2009

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char x[100];
int n,i,j,m;
cout<<"enter the number of characters in the string"<<endl;
cin>>n;
cout<<"enter the string"<<endl;
cin>>x;
for(i=0;i<n;i++)
{
  for(j=0;j<n-i-1;j++)
  {  if(x[j]>x[j+1])
     { m=x[j];
       x[j]=x[j+1];
       x[j+1]=m;
     }
   }
 }
 cout<<"string in sort form: ";
 for(i=0;i<n;i++)
 cout<<x[i];
 getch();
 }

0 comments: