Palindrome substrings question

In the question where we need to find palindrome substrings in a given string , I wrote the below code, could you kindly point out what is the mistake that I am doing in it ?
#include
#include
using namespace std;
int main() {
char a[1000];
cin.getline(a,1000);

int len;
len= strlen(a)-1;
int cnt = 0;
for(int i =0;i<len;i++)
{
	for(int j=0;j<len;j++)
	{
		int x,y;
		x=i;
		y=j;
		int flag = 0;
		while(x<=y)
		{
			if(a[x]!=a[y])
			{
				flag++;
			}
			x++;
			y--;
		}
		if(flag==0)
		{
			cnt++;
		}
	}
}
cout<<cnt;
return 0;

}

hi @agganushka_9eb7cecc88bfac61
refer this -->

int countSubstrings(string s) {
        int n = s.size();
        bool dp[n][n];
        int ans = 0;
        
        for(int i=0;i<n;i++){
            int row = 0;
            int col = i;
            
            while(col < n){
                if(i == 0){
                    dp[row][col] = true;
                }
                else if(i == 1){
                    dp[row][col] = s[row] == s[col];
                }
                else{
                    dp[row][col] = false;
                    if(s[row] == s[col] && dp[row+1][col-1] == true){
                        dp[row][col] = true;
                    } 
                }
                if(dp[row][col]){
                    ans++;
                }
                row++;
                col++;
            }
        }
        return ans;
    }

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.