Special
array reversal
Given a string S, containing special characters
and all the alphabets, reverse the string without
affecting the positions of the special
characters.
#include <stdio.h>
#include <string.h>
main()
{
char s[20],temp;
int i=0,j;
gets(s);
j=strlen(s)-1;
while(i<j)
{
if(isalpha(s[i]) && isalpha(s[j]))
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
i++;j--;
}
else if(isalpha(s[i]))
j--;
else
i++;
}
puts(s);
}
Output:
No comments:
Post a Comment