Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to print the fibonacci series using recursion in reverse order within class using PHP

1 Answer

0 votes
class Fibonacci
{
    function __construct() {
    }
    
    static function fib($total, $initial, $next) {
        if ($total > 0) {
            Fibonacci::fib($total - 1, $next, $next + $initial);
            echo "  " . $initial;
        }
    }
    
    public static function main()
    {
        $total = 6;
        echo "Fibonacci series of " . $total . " Elements  :";
        Fibonacci::fib($total, 0, 1);
        
        $total = 10;
        echo "\nFibonacci series of " . $total . " Elements :";
        Fibonacci::fib($total, 0, 1);
    }
}

Fibonacci::main();




/*
run:

Fibonacci series of 6 Elements  :  5  3  2  1  1  0
Fibonacci series of 10 Elements :  34  21  13  8  5  3  2  1  1  0

*/

 



answered Nov 29, 2023 by avibootz
...