Find next palindrome prime | C # program to find next palindromic prime for a given number . ; if ( 8 <= N <= 11 ) return 11 ; generate odd length palindrome number which will cover given constraint . ; if y >= N and it is a prime number then return it . ; Driver code
using System ; using System . Text ; using System . Collections ; class Geeks { static bool isPrime ( int num ) { if ( num < 2 num % 2 == 0 ) return num == 2 ; for ( int i = 3 ; i * i <= num ; i += 2 ) if ( num % i == 0 ) return false ; return true ; } static int primePalindrome ( int N ) { if ( 8 <= N && N <= 11 ) return 11 ; for ( int x = 1 ; x < 100000 ; ++ x ) { string s = x . ToString ( ) ; char [ ] buffer = s . ToCharArray ( ) ; Array . Reverse ( buffer ) ; int y = Int32 . Parse ( s + new string ( buffer ) . Substring ( 1 ) ) ; if ( y >= N && isPrime ( y ) == true ) return y ; } return - 1 ; } public static void Main ( ) { Console . WriteLine ( primePalindrome ( 112 ) ) ; } }