Find third number such that sum of all three number becomes prime | Function that will check whether number is prime or not ; Function to print the 3 rd number ; If the sum is odd ; If sum is not prime ; Driver code
function prime ( n ) { for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } function thirdNumber ( a , b ) { let sum = 0 , temp = 0 ; sum = a + b ; temp = 1 ; if ( ( sum & 1 ) != 0 ) { temp = 2 ; } while ( ! prime ( sum + temp ) ) { temp += 2 ; } document . write ( temp ) ; } let a = 3 , b = 5 ; thirdNumber ( a , b ) ;