PHP processing Fibonacci Sequence Non-recursive method _php Tutorial

Source: Internet
Author: User
I conceived it myself, and the fact that the program solves the problem is an offset. First look at the series:: 1, 1, 2, 3, 5, 8, 13, 21, 34 the next number of series is the sum of the first 2 numbers, and so on.
Program processing, is actually a for statement, the traditional for statement is for ($i =1; $i; $count, $i + +), where the offset is $i= $i +1. If this sequence is processed, the offset is not 1, which is the first 1 digits. So when you have a for, a variable records the previous number, the other one records the current number, the offset is the number, and then it is re-assigned in the loop, and the previous number is recorded as a course loop value, which is the offset of the next loop. The code is actually simple:
Copy CodeThe code is as follows:
$count = 9999999999967543;
$array = Array (' 0′=>1);
For ($a =1, $i =2; $i < $count; $i = $i + $a) {
$array [] = $a;
$array [] = $i;
$a = $a + $i;
}
Print_r ($array);
echo $count. ' There '. Count ($array). ' A Fibonacci number ';

Suggest which boring people take this to phpchina to the cabbage profession top sticker

http://www.bkjia.com/PHPjc/324859.html www.bkjia.com true http://www.bkjia.com/PHPjc/324859.html techarticle I conceived it myself, and the fact that the program solves the problem is an offset. First look at the series:: 1, 1, 2, 3, 5, 8, 13, 21, 34 the next number of series is the first 2 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.