Monday, 25 June 2012


C program to reverse a string using recursion


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



output:
       

3 comments:

Ekeeda said...

This is a really informative knowledge, Thanks for posting this informative Information. Manipal university video lectures

Aorta Digital Services said...

Very informative program for C learner. SEO training in Chennai

RobertNelson said...

Thank you for posting such a great blog. I found your website perfect for my needs. Read About Fermented moringa