Search This Blog

Loading...

Reverse a string without using a Loop or using Recursion

#include<stdio.h>
#define MAX 10000

char* getReverse(char str[]){

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

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

    return rev;
}


int main(){

    char str[MAX],*rev;

    clrscr();

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

    rev = getReverse(str);

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


Output: 
Enter string : AbCdefG
Reversed string is : GfedCbA

1 comment: