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
< ? php function series ( $ n , $ d ) { if ( $ d == 0 ) { for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo "0 ▁ " ; echo " STRNEWLINE " ; return ; } if ( $ n % 2 == 0 ) { for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { echo pow ( -1 , $ i ) * $ d , " " ; } echo " STRNEWLINE " ; } else { $ m = $ n ; $ r = ( $ m / ( $ m - 1 ) ) ; $ g = ( $ d * sqrt ( $ r ) ) ; echo "0 ▁ " ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { echo pow ( -1 , $ i ) * $ g , " " ; } echo " STRNEWLINE " ; } } $ n = 3 ; $ d = 3 ; series ( $ n , $ d ) ; ? >