Users Online
· Guests Online: 86
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C Program to Check whether a given String is Palindrome or not using Recursion
The following C program, with recursion, determines whether the entered string is a palindrome or not. A palindrome is a word, phrase or sentence that reads the same backward or forward.
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Check whether a given String is Palindrome or not
* using Recursion
*/
#include <stdio.h>
#include <string.h>
void check(char [], int);
int main()
{
char word[15];
printf("Enter a word to check if it is a palindrome\n");
scanf("%s", word);
check(word, 0);
return 0;
}
void check(char word[], int index)
{
int len = strlen(word) - (index + 1);
if (word[index] == word[len])
{
if (index + 1 == len || index == len)
{
printf("The entered word is a palindrome\n");
return;
}
check(word, index + 1);
}
else
{
printf("The entered word is not a palindrome\n");
}
}}
$ gcc palindrome.c -o palindrome
$ a.out
Enter a word to check if it is a palindrome
malayalam
The entered word is a palindrome
Here is the source code of the C program to display a linked list in reverse. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Check whether a given String is Palindrome or not
* using Recursion
*/
#include <stdio.h>
#include <string.h>
void check(char [], int);
int main()
{
char word[15];
printf("Enter a word to check if it is a palindrome\n");
scanf("%s", word);
check(word, 0);
return 0;
}
void check(char word[], int index)
{
int len = strlen(word) - (index + 1);
if (word[index] == word[len])
{
if (index + 1 == len || index == len)
{
printf("The entered word is a palindrome\n");
return;
}
check(word, index + 1);
}
else
{
printf("The entered word is not a palindrome\n");
}
}}
$ gcc palindrome.c -o palindrome
$ a.out
Enter a word to check if it is a palindrome
malayalam
The entered word is a palindrome
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.