Triangular Numbers | Returns true if ' num ' is triangular , else false ; Base case ; A Triangular number must be sum of first n natural numbers ; Driver code
< ? php function isTriangular ( $ num ) { if ( $ num < 0 ) return false ; $ sum = 0 ; for ( $ n = 1 ; $ sum <= $ num ; $ n ++ ) { $ sum = $ sum + $ n ; if ( $ sum == $ num ) return true ; } return false ; } $ n = 55 ; if ( isTriangular ( $ n ) ) echo " The ▁ number ▁ is ▁ a ▁ triangular ▁ number " ; else echo " The ▁ number ▁ is ▁ NOT ▁ a ▁ triangular ▁ number " ; ? >