In this program, you'll learn to check a given string is Palindrome or not. A string is called Palindrome, if the original string and reverse string of original string are same. To check if a string is palindrome or not follow below steps: 1) Declare two string: f and r. 2) Find Reverse of string. 3) Check if the reversed string is equal to the given string.
#include<stdio.h>
#include<conio.h>
void main()
{
int f, r, len=0;
char str[20];
//clrscr();
printf("Enter the string: ");
scanf("%s", str);
// First calculate the length of string
while(str[len] != '\0')
{
len++;
}
f = 0;
r = len-1;
while(f <= r)
{
if(str[f++] != str[r--])
{
printf("String is not Palindrome");
return;
}
}
printf("String is Palindrome");
getch();
}
Enter the string: nitin
String is Palindrome
Enter the string: ramesh
String is not Palindrome