C Program to Reverse a String Using Recursion

C Program to Reverse a Sting Using Recursion –  If you are looking for reversing a string in C program, this article will help you to guide how to reverse a string in C using recursion. Just go through this reverse string tutorial you will be able to write a  C program to reverse a string.

C Programming Tutorials

CodingCompiler.com presenting series of C programming tutorials for beginners, experienced to advanced learners. These programming tutorials help C learners, students, B.Tech graduates to enhance their C programming skills and hands-on experience.

C Program To Reverse a String with Using Function

C Program To Reverse a String without Using Function

C Program To Reverse a String Using Pointers

This is the sixth C programming example in the series, it helps newbies in enhancing C programming and land on their dream job. All the best guys in learning c programming with coding compiler website.

C Program to Reverse a String Using Recursion

Learn how to reverse a string in C programming in this tutorial. Reversing a string in C programming language can be done using various techniques, but here in this program, we show how to reverse a string using recursion.

C Program To Reverse a String Source Code

Copy paste the below source code or write your own logic into C compilers and run the program to see the result.

/* C PROGRAM TO REVERSE a STRING - REVERSESTRINGRECURSION.C */

#include <stdio.h>
#include <string.h>
 
void reverse(char*, int, int); //Method
 
int main()
{
   char a[100];  //Variables
 
   gets(a);
 
   reverse(a, 0, strlen(a)-1);
 
   printf("%s\n",a);
 
   return 0;
}
 // Logic for reversing a string
void reverse(char *x, int begin, int end) //Recursion
{
   char c;
 
   if (begin >= end)
      return;
 
   c          = *(x+begin);
   *(x+begin) = *(x+end);
   *(x+end)   = c;
 
   reverse(x, ++begin, --end);
}

C Program To Reverse a String Output

After you compile and run the above program, your C compiler asks you to enter a string to reverse. After you enter a string, recursive function will reverse the string and show output like below expected output.

Input a string

programming

Reverse of entered string is

gnimmargorp

Read Other C Programming Tutorials:

C Program To Swap Two Numbers Using Two Variables

C Program To Swap Two Numbers Using Three Variables

C Program For Prime Numbers – Check  a Number is Prime or Not

C Program To Reverse a String with Using Function

C Program to Reverse a String without Using Function

Leave a Comment