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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz