Question

Can someone help me with this PHP code thank you in advance!! Write a PHP program...

Can someone help me with this PHP code thank you in advance!!

Write a PHP program to print the first 10 terms of a Fibonacci sequence. You need to use arrays to store and print the terms. In the Fibonacci sequence, the next number is found by adding up the two numbers before it. The Fibonacci Sequence starts with 0 and 1 as the first two terms. So F[0]=0 and F[1]=1 and the series propagates such that F[n]= F[n-1]+F[n-2]. The sequence has the following form 0, 1, 1, 2, 3, 5, 8, 13… and so on…

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello, here is the completed code you wanted. Every important statement is explained using comments. Please check and let me know if you have any doubts. Thanks.

CODE

<?php
//declaring array for stroe Fibonacci sequence
$F=array();

//initializing first two terms
$F[0]=0;
$F[1]=1;

//calculating and storing next terms of sequence
for($i = 2; $i < 10; $i++)
{
    // F[n]= F[n-1]+F[n-2]
    $F[$i]=$F[$i-1]+$F[$i-2];
}

//printing Fibonacci sequence
for($i = 0; $i < 10; $i++)
{
    echo " ".$F[$i]." ";
}
?>

OUTPUT

CODE SCREEN SHOT

Add a comment
Know the answer?
Add Answer to:
Can someone help me with this PHP code thank you in advance!! Write a PHP program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • Can someone please help me with this problem? Thank you in advance! 3. (10 points) Let...

    Can someone please help me with this problem? Thank you in advance! 3. (10 points) Let X1, X2, ... be a sequence of random variables with common uniform distribution on (0,1). Also, let Zn = (11=1 X;)/n be the geometric mean of X1, X2, ..., Xn, n=1,2,.... Show that In , where c is some constant. Find c.

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • Can someone help me write a retirement calculator program in c code. I want to write...

    Can someone help me write a retirement calculator program in c code. I want to write a program that the user can enter their age, amount they wish to save each month, the interest rate, and the age they wish to retire. I would like to use a switch loop, if else loop or do while loop. the output should show them how much they should have in a retirement savings account at the age they wish to retire at....

  • c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8,...

    c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...

  • This is a PHP code. It is a project of roman converter Can someone explain this...

    This is a PHP code. It is a project of roman converter Can someone explain this statement to me? What does it mean? $romanValid = "/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/"; and in the second function, what does the first&neighbor stand for? can you explain the logic of this function for me, please?? thank you function validRoman($str) $romanValid = "/"M{0,4}(CM CD D2C{0,37) (XC XL L?X{0,33) (IX IVV?10,3)/": return (preg_match($romanValid, $str)); function RomanToNum($str) $first = 0; $neighbor = 0; $result = 0; $len = strlen($str); for...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous...

    USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8,13, So, if f(1)-1 and f(2) -1, then f(3)-2)+f(1) We can represent this pattern as f(x) - f(x-1)+f(x-2). A Fibonacci sequence can be created with any two numbers. Prompt the user to enter the first two numbers in a Fibonacci sequence and the total number of elements requested in the sequence....

  • Can someone please help me with this code? I'm writing in C++. Thank you in advance....

    Can someone please help me with this code? I'm writing in C++. Thank you in advance. Complete a program that represents a Magic Eight Ball (a Magic Eight Ball allows you to ask questions and receive one of several random answers). In order to complete this, you will need a couple of new functions. First, in order to get a line of input that can contain spaces, you cannot use cin, but instead will use getline: string question; cout <<...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT