getting NZEC plese resolve !!

#include<stdio.h>
int prime(long int a);
int palindrome(long int a);

int main()
{
long int a;
scanf("%ld",&a);
if(a <= 1000000)
while(1)
{
if(palindrome(a)){
if(prime(a)) {printf("%ld",a);return;}
}
a=a+1;
}
return 0;
}
int prime(long int a){
long int i;
for(i=2;i<=a/2;i++) if(a%i==0)return 0;

return 1;
}

int palindrome(long int a){
long int temp=a,reverse=0;
while( temp != 0 ){
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if(reverse == a) return 1;
else return 0;
}

It is because your code do not return 0.

Inside while(1) add 0 after return,

while(1)
    {
     if(palindrome(a)){
     if(prime(a)) {printf("%ld",a);return 0;}
    }

Here is AC version of your code : http://www.codechef.com/viewsolution/5623820

thanks a ton !!!

bro most welcome… :slight_smile:

i agree with what @rishabhprsd7 said but your code can be made more efficient by by running the loop upto sqrt(a) in place of a/2 . you dont need to go upto a/2 for checking prime .