To check the given string is palindrome
(or) not
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20], rev[20];
int i, j, l;
clrscr();
printf("Enter a string : ");
scanf("%s", str);
for(l = 0; str[l] != '\0'; l++);
for(i = l - 1, j = 0; i >= 0; i--, j++)
rev[j] = str[i];
rev[j] = '\0';
if(stricmp(str, rev) == 0)
printf("\nThe given string is a palindrome");
else
printf("\nThe given string is not a palindrome");
getch();
}
Output:
Case: 1
Enter a string : madam
The given string is a palindrome
Case: 2
Enter a string : malayalam
The given string is a palindrome
Case: 3
Enter a string : liril
The given string is a palindrome
Case: 4
Enter a string : bhuvan
The given string is not a palindrome
-
UpdatedDec 31, 2019
-
Views6,389
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order