Friday, 26 November 2010

write a recursive function to reverse a string

//write a recursive function to reverse a string
#include<stdio.h>
#include<conio.h>
void main()
{
 void reverse();
 clrscr();
 printf("enter any string\n");
 reverse();
 getch();
// scanf("%d");//but we need to enter any value or letter to see o/p
}
//
void reverse()
{
 char ch;
 ch=getchar();
 if(ch!='\n')
 {
  reverse();
  printf("%c",ch);
  //putchar(ch);
  }
 }

No comments:

Post a Comment