I am guessing something is not right. When I input a palindrome string for example 'madam' is says Not palindrome. Your help is appreciated.
#include<iostream.h>
#include<string.h>
//#include<stdlib.h>
int main()
{
//clrscr();
char arr[20]; //array to hold string
int len,ans=0,x,y;
cout<<"Enter : ";
cin>>arr; // string input
len=strlen(arr); // finding out string length,using a lib func
for (x=0,y=(len-1); x!=y ; x++,y--) //multiple var for loop
{
if (arr[x] == arr[y]) //increment palindrome checking counter ans++;
if (ans == (len/2) )// if palindrome checking counter is equal to half the string length,output"palindrome"
{
cout<<"Its a palindrome !!";
}
}
cout<<"Not a palindrome !";
return 0;
}