Problem Description
Code for Sort given string in ascending orderCODING ARENA
#include <stdio.h>
#include<string.h>
int main()
{
char str[100],temp;
int i,j;
scanf("%s",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",str);
return 0;
}
Test Case 1
Input (stdin)sample
Expected Outputaelmps
Test Case 2
Input (stdin)string
Expected Outputginrst
No comments:
Post a Comment