C Program to Reverse String using Recursion

C Program to Reverse String using Recursion:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
main()
{
    char str[10];
    void revs(char[]);
    printf("Enter the string to reverse \n");
    gets(str);
    printf("Reverse of string is \n");
    revs(str);
}

void revs(char *s)
{
       if(*s=='\0')
           return;
        revs(s+1);
        printf("%c",*s);
}

OUTPUT:

Enter the string to reverse
BaronTuts
Reverse of string is
stuTnoraB

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − 1 =