Sunday, March 10, 2024

C Language Recursive Function Program To Reverse A String

 #include <stdio.h>
#include <string.h>

void rev(char [],int, int);

int main()
{   char ch[100];
   printf("Enter a string:");
   scanf("%s",ch);
   printf("\nEntered string is %s",ch);
 rev(ch,0,strlen(ch)-1); 
      return 0;
}

void rev(char ch[],int i,int end)
{
    char c;
   if(end<=i)
   {
      printf("\nReverse=%s",ch);
       return ;
   }
      c=ch[i];
       ch[i]=ch[end];
       ch[end]=c;
   i++;
   end--;
   rev(ch,i,end);    
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner