C Program to Reverse the String using Recursion

C Program :

/* Aim: Write a function which displays a string in reverse order (Use Recursion)*/
#include<stdio.h>
#include<string.h>
#define size 100
void re_StrRev(char str[],int i); // re_StrRev Function Prototype
void main()
{
char str[size];
printf("\n Enter any string:-");
scanf("%s",str);
printf("\n");
re_StrRev(str,strlen(str)-1);
printf("\n \n");
} // End of main
// re_StrRev Function
void re_StrRev(char str[],int i)
{
if(i>=0)
{
printf("%c",str[i]);
re_StrRev(str,i-1);
}
} // End of re_StrRev Function
/* Ouput of above code:-
[root@localhost Computer Science C]# cc e12b3.c
[root@localhost Computer Science C]# ./a.out
Enter any string:-Halo
olaH
*/
view raw re_StrRev.c hosted with ❤ by GitHub
Get This Program: