Smarandache | Function to collect first ' n ' prime numbers ; List to store first ' n ' primes ; Function to generate Smarandache - Wellin Sequence ; Storing the first ' n ' prime numbers in a list ; Driver Code
function primes ( n ) { var i = 2 ; var j = 0 ; var result = Array ( n ) var z = 0 ; while ( j < n ) { var flag = true ; for ( var item = 2 ; item <= parseInt ( i * 1 / 2 ) ; item ++ ) if ( i % item == 0 && i != item ) { flag = false ; break ; } if ( flag ) { result [ z ++ ] = i ; j += 1 ; } i += 1 ; } for ( i = 0 ; i < 5 ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) document . write ( result [ j ] ) ; document . write ( " " ) ; } } function smar_wln ( n ) { primes ( n ) ; } var n = 5 ; document . write ( " " + n + " " ) ; smar_wln ( n ) ;