The next pal

i have tested many input cases for my next palindrome problem it is running fine in my dev c++ compiler…but it is showing wrong ans why?

int main()

{

    long int i=0,sum,num,n,k,r,c=0,m,z;
    long int arr[10000];
	scanf("%ld",&n);
	for(k=0;k<n;k++)
	{
		scanf("%ld",&arr[k]);
	}
    while(i<n)
    {
		m=arr[i];
	while(m<=100000000)
	{    
		z=m+1;
		k=m+1;
		sum=0;
		while(k>0)
		{
			r=k%10;
			k=k/10;
			sum = sum *10+r;
		}
		
		if (sum==z)
		{
			printf("%ld\n",z);
			c=1;
		}
		if(c==0)
		m=m+1;
		else
		break;
     
	}
	
	i=i+1;
	c=0;
    }
return 0;
}

Acc. to the Question you have to solve it for 1000000 digits
You are using an long int for that…which covers only max of 10 digits…

I hv checked it against 99999999999999998 which acc to question must give 99999999999999999…
So nw u know where were u wrong…
Hope it helped.
Happy coding!!!

1 Like