QUESTION:
Given a string, we have to reverse the string without changing the position of punctuations and spaces.
Sample: house no : 123@ cbe
Output: ebc32 1o : nes@ uoh
PROGRAM:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[100],b[100];
int i,k=0;
scanf("%[^\n]s",a);
for(i=0;i<strlen(a);i++)
{
if((a[i]>=97 && a[i]<=122) || (a[i]>=48 && a[i]<=57))
{
b[k]=a[i];
k++;
}
}
for(i=0;i<strlen(a);i++)
{
if((a[i]>=97 && a[i]<=122) || (a[i]>=48 && a[i]<=57))
{
printf("%c",b[k-1]);
k--;
}
else
printf("%c",a[i]);
}
}
Comments
Post a Comment