How to do a program for reverse of string?

CODE




How to do a program for reverse of string?

//Write a program for reverse of string…

int main()
{
    char a[20],b[20];
    int i,c;
    printf("\n enter name:");
    gets(a);
    for(i=0;i<a[i]!='\0';i++);
    c=i-1;
    for(i=0;a[i]!='\0';i++)
    {
        b[c-i]=a[i];
    }
    b[i]='\0';
    for(i=0;b[i]!='\0';i++)
    {
        a[i]=b[i];
    }
    a[i]='\0';
    printf("\n reversed array:\n %s",a);
}


Output:
enter name: smile

 reversed array:
 elims

How to do a program for reverse of string? How to do a program for reverse of string? Reviewed by Unknown on January 01, 2019 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.