eg.
MADAM is palindrome
MAIDEN is not a palindrome.
#include<stdio.h>
void main()
{
char text[50] , rev[50];
clrscr();
cout<< "\n Enter a string : ";
gets(text);
/* calculate the length of the string */
int len = strlen(text);
/* reverse the string */
for(int i = len - 1, k = 0; i>=0 ; i--, k++)
{
rev[k] = text[i];
}
rev[k] = '\0';
if(strcmp(text, rev) == 0)
cout<< "\n The string " << text << " is a palindrome. ";
else
cout<< "\n The string " << text << " is not a palindrome. ";
getch();
}
MADAM is palindrome
MAIDEN is not a palindrome.
#include <iostream.h>
#include <conio.h>
#include<string.h>#include<stdio.h>
void main()
{
char text[50] , rev[50];
clrscr();
cout<< "\n Enter a string : ";
gets(text);
/* calculate the length of the string */
int len = strlen(text);
/* reverse the string */
for(int i = len - 1, k = 0; i>=0 ; i--, k++)
{
rev[k] = text[i];
}
rev[k] = '\0';
if(strcmp(text, rev) == 0)
cout<< "\n The string " << text << " is a palindrome. ";
else
cout<< "\n The string " << text << " is not a palindrome. ";
getch();
}
No comments:
Post a Comment