Saturday, 12 March 2011

Write a program that will read a string and rewrite it in the alphabetical order. i.e. the word STRING should be written as GINRST

#include<stdio.h>
#include<conio.h>
main()
{
char str[100],temp;
int i,j;
clrscr();
printf("Enter the string :");
gets(str);
printf("%s in ascending order is -> ",str);
for(i=0;str[i];i++)
{
for(j=i+1;str[j];j++)
{
if(str[j]<str[i])
{
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
}
}
printf("%s\n",str);
getch();
}
Output:
Enter the string :string
string in ascending order is -> ginrst

1 comment:

  1. Write a program which contains a class called BraceMatch. The class should contain data members capable of holding an expression. The expression will contain parenthesis (curly braces whose opening and closing braces should match). The class should contain a member function which is capable of reporting if the opening and closing braces match and in case they do not, it should report as to which is more (i.e are there more opening braces than closing braces or not) and how many are needed to complete a pair. Make use of a pointer to a class in order to achieve this. You may use constructors, any data member or member functions which in your opinion can help in solving the problem.
    PLEASE GIVE THE PROGRAME

    ReplyDelete