Printing a String in Reverse order using recursion

Problem Statement
Write a c program to do the following
  1. scan a string of word
  2. print the words in reverse order by using recursion

#include<stdio.h>
void reverse(char string[],int i);
int main()
{
  char string[20];
  printf("enter the string \n");
  scanf("%s",string);
  printf("the string entered by you is ");
  printf("%s \n",string);
  printf("now i print in the reverse order ");
  reverse(string,0);
  return 0;
}
void reverse(char string[],int i)
{
  if(string[i]=='\0')
    {
      return ;
    }
  else
    {
      reverse(string,i+1);
      printf("%c",string[i]);
    }
  return ;
}



No comments:

Post a Comment