In this C program, we will learn how to write a program to reverse a string without using strrev() using Recursion.
Here is the code of the program to reverse a string without using strrev() using Recursion.
/* C program to Reverse a String without using strrev() using Recursion */
#include <stdio.h>
#include <string.h>
void reverse_String(char [], int, int);
void main()
{
char Str[100], temp;
int i, len;
printf("Enter a String: ");
gets(Str);
len = strlen(Str);
reverse_String(Str, 0, len -1);
printf("Reverse String is = = %s", Str);
}
void reverse_String(char Str[], int i, int len)
{
char temp;
temp = Str[i];
Str[i] = Str[len - i];
Str[len - i] = temp;
if (i == len/2)
{
return;
}
reverse_String(Str, i + 1, len);
}
Enter a String: Tutorialsrack
Reverse String is = = kcarslairotuT
--------------------------------
Process exited after 6.455 seconds with return value 36
Press any key to continue . . .
Comments