Write a C Program that will read a string and rewrite it in the alphabetical order. i.e. the word STRING should be written as GINRST
1: #include<stdio.h>
2: #include<conio.h>
3: int main()
4: {
5: char str[100],temp;
6: int i,j;
7: clrscr();
8: printf("Enter the string :");
9: gets(str);
10: printf("%s in ascending order is -> ",str);
11: for(i=0;str[i];i++)
12: {
13: for(j=i+1;str[j];j++)
14: {
15: if(str[j]<str[i])
16: {
17: temp=str[j];
18: str[j]=str[i];
19: str[i]=temp;
20: }
21: }
22: }
23: printf("%s\n",str);
24: getch();
25: return 0;
26: }
No comments:
Post a Comment