Given N and Standard Deviation , find N elements | Function to print series of n elements ; If S . D . is 0 then print all elements as 0. ; Print n 0 's ; If S . D . is even ; Print - SD , + SD , - SD , + SD ; If odd ; Convert n to a float integer ; Print one element to be 0 ; Print ( n - 1 ) elements as xi derived from the formula ; Driver Code
function series ( n , d ) { if ( d == 0 ) { for ( let i = 0 ; i < n ; i ++ ) document . write ( " " ) ; document . write ( ) ; return ; } if ( n % 2 == 0 ) { for ( let i = 1 ; i <= n ; i ++ ) { document . write ( Math . pow ( - 1 , i ) * d + " " ) ; } document . write ( ) ; } else { let m = n ; let r = ( m / ( m - 1 ) ) ; let g = ( d * ( Math . sqrt ( r ) ) ) ; document . write ( " " ) ; for ( let i = 1 ; i < n ; i ++ ) { document . write ( Math . pow ( - 1 , i ) * g + " " ) ; } document . write ( ) ; } } let n = 3 , d = 3 ; series ( n , d ) ;