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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad