Tuesday, 3 June 2014

String Sorting

                                String Sorting


A simple program which will sort the characters stored in the string entered by user.


#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int i,j;
char a[20];
char t;
cout<<"enter a string :";
gets(a);
for(int j=0;j<=strlen(a);j++)
{
for(int i=0;i<=strlen(a);i++)
{
if(a[i]<a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
for(i=strlen(a);i>0;i--)
{
cout<<a[i];
}


getch();
return 0;
}

No comments:

Post a Comment