Check whether given number N is a Moran Number or not | Function to calculate digit sum ; Function to check if number is prime ; Function to check if number is moran number ; Calculate digit sum ; Check if n is completely divisible by digit sum ; Calculate the quotient ; Check if the number is prime ; Driver code
function digSum ( a ) { let sum = 0 ; while ( a ) { sum += a % 10 ; a = Math . floor ( a / 10 ) ; } return sum ; } function isPrime ( r ) { let s = true ; for ( let i = 2 ; i * i <= r ; i ++ ) { if ( r % i == 0 ) { s = false ; break ; } } return s ; } function moranNo ( n ) { let dup = n ; let sum = digSum ( dup ) ; if ( n % sum == 0 ) { let c = n / sum ; if ( isPrime ( c ) ) { document . write ( " " ) ; return ; } } document . write ( " " + " " ) ; } let n = 21 ; moranNo ( n ) ;