Monday, 27 January 2014

Write a recursive function to find out the reverse of a string using pointers. Eg. yashwant o/p; tnawhsay

QUES=>Write a recursive function to find out the reverse of a string using pointers. Eg. yashwant o/p; tnawhsay.

CODE=>

#include<stdio.h>
#include<conio.h>
#include<string.h>
void rev(char *a,int l);  
void main()
{
int l,i;
char *n;
clrscr();
printf("ENTER THE STRING:");
gets(n);
l=strlen(n);
rev(n,l);
getch();
}
void rev(char *a,int l)
{
if(l==0)
{
printf("%c",*(a+l));
}
else
{
printf("%c",*(a+l));
rev(a,l-1);
}

}

OUTPUT=>


No comments:

Post a Comment