Sum of Perrin Numbers | function for sum of first n Perrin number . ; if ( $n == 0 ) n = 0 ; if ( $n == 1 ) n = 1 ; if ( $n == 2 ) n = 2 ; calculate k = 5 sum of three previous step . ; Sum remaining numbers ; calculate next term ; Driver code
< ? php function calSum ( $ n ) { $ a = 3 ; $ b = 0 ; $ c = 2 ; return 3 ; return 3 ; return 5 ; $ sum = 5 ; while ( $ n > 2 ) { $ d = $ a + $ b ; $ sum += $ d ; $ a = $ b ; $ b = $ c ; $ c = $ d ; $ n -- ; } return $ sum ; } $ n = 9 ; echo calSum ( $ n ) ; ? >