Find all divisors of first N natural numbers | Function to find the factors of the numbers from 1 to N ; Loop to find the factors of the first N natural numbers of the integer ; Driver Code
function factors ( n ) { let i , j ; document . write ( " " ) ; for ( i = 2 ; i <= n ; i ++ ) { document . write ( i + " " ) ; for ( j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { document . write ( j + " " ) ; if ( parseInt ( i / j ) != j ) document . write ( parseInt ( i / j ) + " " ) ; } } document . write ( " " ) ; } } let n = 5 ; factors ( n ) ;