Reverse a string using recursion in c





C code to reverse a string by recursion:

#include<stdio.h>
#define MAX 100
char* getReverse(char[]);

int main(){

    char str[MAX],*rev;

    printf("Enter  any string: ");
    scanf("%s",str);

    rev = getReverse(str);

    printf("Reversed string is: %s",rev);
    return 0;
}

char* getReverse(char str[]){

    static int i=0;
    static char rev[MAX];

    if(*str){
         getReverse(str+1);
         rev[i++] = *str;
    }

    return rev;
}

Sample output:

Enter any string: mona
Reversed string is: anom





Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples
Post a Comment