Programming Examples
C program to read a line and print it reverse using recursive function.
Write a C program to read a line and print it reverse using recursive function.
Solution
//Write a C program to read a line and print it reverse using recursive function.
#include<stdio.h>
void reverse(char *);
int main()
{
char str[50];
int a,b;
printf("Enter String : ");
gets(str);
printf("Reverse String : ");
reverse(str);
return 0;
}
void reverse(char *ptr)
{
if(*ptr!='\0')
{
reverse(ptr+1);
printf("%c",*ptr);
}
}
Output
Enter String : infomax
Reverse String : xamofni