//Hi,can someone explain the meaning of [size -2],why not [size -1],if we narrowing the string
int palindrome(char str[], int size);
int main()
{
cout << "Enter a string: ";
char str[20];
cin.getline(str,20,'\n');
cout << "The entered string " << ( (palindrome(str,strlen(str)+1))? "is":"is not" ) << " a Palindrome string." << endl;
return 0;
}
int palindrome(char str[], int size)
{
if (str[0] != str[size-2]) //if first element is not equal to last element.
return 0;
else if (strlen(str) <= 1)
return 1;
else
return palindrome(str+1,size-2);
}
aluhnev 0 Junior Poster in Training
tinstaafl 1,176 Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.