Moonbat
07-13-2008, 08:01 PM
For more info visit this thread - http://www.all-nettools.com/forum/showthread.php?t=76**
The Problem - "Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million."
The Solution :)
<?php
/*********************************
* The Euler Project #2 Solution *
* Coded By Moonbat *
* July **, 2008 *
*********************************/
$first = 0; // Here are the two numbers that...
$second = *; // ...we have to start with
$wing = array(); // Keeping ***** of the even-numbered Fibonacci numbers
for ($i=0; $i<=**; $i++) {
$fibonacci = $first + $second; // 0+*, *+*, *+2, 2+*
$first = $second; // 0-->*, *-->*, *-->2, 2-->*
$second = $fibonacci; // *-->2, 2-->*, *-->5, 5-->8
echo "$fibonacci <br>";
if (($fibonacci &#*7; 2) == 0) { // If the current Fibonacci number is even
$wing[$i] = $fibonacci;
} else {
echo "";
}
}
$arraysum = array_sum($wing); // Add 'em all up!
echo "<hr>" . $arraysum;
?>
The Problem - "Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million."
The Solution :)
<?php
/*********************************
* The Euler Project #2 Solution *
* Coded By Moonbat *
* July **, 2008 *
*********************************/
$first = 0; // Here are the two numbers that...
$second = *; // ...we have to start with
$wing = array(); // Keeping ***** of the even-numbered Fibonacci numbers
for ($i=0; $i<=**; $i++) {
$fibonacci = $first + $second; // 0+*, *+*, *+2, 2+*
$first = $second; // 0-->*, *-->*, *-->2, 2-->*
$second = $fibonacci; // *-->2, 2-->*, *-->5, 5-->8
echo "$fibonacci <br>";
if (($fibonacci &#*7; 2) == 0) { // If the current Fibonacci number is even
$wing[$i] = $fibonacci;
} else {
echo "";
}
}
$arraysum = array_sum($wing); // Add 'em all up!
echo "<hr>" . $arraysum;
?>