String Reverse using Recursion C Program


This program is for Reversing a String Using Recursion. This is a part of Mumbai University MCA Colleges C Program and Data Structure MCA





#include<stdio.h>
#include<conio.h>
void revstring(char[],int);

void main()
{
          char str[20];
          clrscr();
         
          /* accept a string from the user */
          printf("\n Enter the string\n");
          fflush(stdin);
          gets(str);
 
          /*print the original string */
          printf("\n original string: %s\n",str);

          printf("\n Reversed string: ");
          revstring(str,0);
          getch();
 }

void revstring(char str[],int n)
{
          /* check for null string */
          if(str[n]=='\0')
                   return;

          revstring(str,n+1);
          printf("%c",str[n]);
}






OUTPUT:

Enter the string:       Data Structures

Original String:         Data Structures

Reversed String:       serutcurtS ataD



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment