Ad

Friday, February 22, 2013

Reverse a String by using Recursion......

Assalamu Alaikum.... How are you, everyone ? Today I will show how to reverse a string by using recursion in C programmimg. To understand  this program you must have a  little bit knowledge about stack. So, let's start..........



#include<stdio.h>
#include<conio.h>


void reverse(char str[], int len)
{
    if(str[len]=='\0')
    {
        return;
    }
    else
    {
        reverse(str, len+1);
    }
    printf("%c", str[len]);
}

int main()
{
    char word[50];

    printf("Enter the word or sentence : ");

    gets(word);

    printf("\n\n");

    reverse(word, 0);

getch();
return 0;
}

Now, just copy-paste the code and save it with .c extension. Try to understand, how it works....... If you have any problem, feel free to write a comment.........

Thanks to All.............

0 comments:

Post a Comment