Try the following code:
#include <iostream>
#include<string>
using namespace std;
char s[30];
int i=0, j, first, last, length,subleng, maxi=0;
void main ()
{
cout<<"Enter a string to process \n";
cin >> s;
length = static_cast<int>(strlen(s));
for(i=0 ; i<length ; i++)
{
int j,k,n;
for (n=0; n<2; n++)
{ j = i-n;
k = i+1;
subleng = n;
while ( j>=0 && k<length && s[j]==s[k])
{
subleng +=2;
j--; k++;
}
if( subleng > maxi)
{
first= j + 1;
maxi= subleng;
}
}
}
cout<<"The longest symmetric substring is : \n";
for (i=0 ; i<maxi ; i++)
{
cout<<s[first+i];
}
cout<<endl<<endl;
}
:)