This is a basic PHP Program to find sum of even index term. Below examples will help you in the better understanding of the basic concept of PHP programming language.
We are using the if…else statement to determine the number of the days in a current month. Copy the below code and execute it with the help of PHP compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?php /** * PHP Program to find sum of even index term */ function evenSum($n) { $C = array(array()); $i; $j; // Calculate value of Binomial for ($i = 0; $i <= $n; $i++) { for ($j = 0; $j <= min($i, $n); $j++) { // Base Cases if ($j == 0 or $j == $i) $C[$i][$j] = 1; else $C[$i][$j] = $C[$i - 1][$j - 1] + $C[$i - 1][$j]; } } // finding sum of even index term. $sum = 0; for ( $i = 0; $i <= $n; $i += 2) $sum += $C[$n][$i]; return $sum; } echo evenSum(4); |
8
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.