Reverse String Till Underscore


C CODE:

#include<stdio.h>
#include <stdlib.h>

int main()
{
char a[100];
fgets(a,100,stdin);
int i,j,k=0,l,g=0;
l=strlen(a);
for(i=0;i<l;i++)
{
    if(a[i]=='_')
    {
        k=i;
        g=1;
    }
}
if(g==1)
{
for(i=k-1;i>=0;i--)
{
    printf("%c",a[i]);
}for(i=k;i<l;i++)
{
    printf("%c",a[i]);
}
}else
{
    for(i=l-1;i>=0;i--)
    {
        printf("%c",a[i]);
    }
}
}

Comments

Post a Comment

Popular posts from this blog

Count of common characters in two strings

RECTANGULAR SUM