text: Check if given number is Emirp Number or not | Returns true if n is prime . Else false . ; Corner case ; Check from 2 to n - 1 ; Function will check whether number is Emirp or not ; Check if n is prime ; Find reverse of n ; If both Original and Reverse are Prime , then it is an Emirp number ; Input number
code: function isPrime ( n ) { if ( n <= 1 ) return false ; for ( i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } function isEmirp ( n ) { if ( isPrime ( n ) == false ) return false ; var rev = 0 ; while ( n != 0 ) { var d = n % 10 ; rev = rev * 10 + d ; n = parseInt ( n / 10 ) ; } return isPrime ( rev ) ; } var n = 13 ; if ( isEmirp ( n ) == true ) document . write ( " " ) ; else document . write ( " " ) ;