Home » C Programs » C Program to Check Palindrome String

C Program to Check Palindrome String

In this program, we can execute the c palindrome for beginners using the recursion method.

Recursion Method in C

When a function in C calls a copy of itself, this is referred to as recursion. To put it another way, when a function calls itself, this is referred to as recursion. You must define an exit condition on that function when employing recursion; else, it will go into an indefinite loop. 

String Definition in C

A string is a collection of characters encircled by double quotation marks. A string is a data type similar to an integer and a floating point unit that is used to represent text rather than numbers in programming. It is made up of a series of characters that may include spaces and numerals. 

C Program to Check Palindrome String

//C Program to Check Palindrome String
#include <stdio.h>
#include <string.h>
void check(char [], int);
int main()
{
char letters[15];
printf("Enter Letter to Check Is It Palindrome Or Not\n");
scanf("%s", letters);
check(letters, 0);
return 0;
}
void check(char letters[], int index)
{
int len = strlen(letters) - (index + 1);
if (letters[index] == letters[len])
{
if (index + 1 == len || index == len)
{
printf("Its a Palindrome\n");
return;
}
check(letters, index + 1);
}
else
{
printf("Not a Palindrome\n");
}
}

Output:

Enter Letter to Check Is It Palindrome Or Not
inlarn
Not a Palindrome