This question was asked in one the technical interview( Under graduate level). This is kind of application for 'replace' feature. You can make it more accurate by putting more constraints.
Ans :
#include<stdio.h>
int main()
{
int i=0;
char str[100],x ='x',y='y' ;
printf("Enter the string\n:");
gets(str);
while(str[i]!='\0')
{
if(str[i]=='a')
{
printf("%c ",x);
printf("%c ",str[i++] );
printf("%c ",y);
}
else
{
printf("%c ",str[i++] );
}
}
return 0;
}
Ans :
#include<stdio.h>
int main()
{
int i=0;
char str[100],x ='x',y='y' ;
printf("Enter the string\n:");
gets(str);
while(str[i]!='\0')
{
if(str[i]=='a')
{
printf("%c ",x);
printf("%c ",str[i++] );
printf("%c ",y);
}
else
{
printf("%c ",str[i++] );
}
}
return 0;
}
0 comments:
Post a Comment