Wednesday, March 2, 2011

Character Arrays and Strings

Write a program which will read a stirng and rewrite it in the alphabetical order. For example, the word STRING should be written as GINRST.

#include <stdio.h>
void main()
{
char str[20],temp;
int i,j;
clrscr();
printf("Enter a word:");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
for(j=0;str[j]!='\0';j++)
{
if(str[i]<str[j])
{
temp=str[j];
str[j]=str[i];
str[i]=temp;
}
else
continue;
}
}
printf("Alphabetical order of your word\n");
printf("%s",str);
getch();
}

No comments:

Post a Comment