Fibonacci Series Using For Loop in PHP
Q. Write a PHP program to generate Fibonacci Series using for loop
<?php
// Number of terms
$n = 10;
// Initialize first two terms
$first = 0;
$second = 1;
// Display the first two terms
echo "Fibonacci Series up to $n terms:<br>";
echo "$first $second ";
// Generate remaining terms
for ($i = 3; $i <= $n; $i++) {
$next = $first + $second;
echo "$next ";
$first = $second;
$second = $next;
}
?>
Q. Write an algorithm to generate Fibonacci Series using for loop in PHP
1. Start 2. Define the number of terms n 3. Initialize first = 0, second = 1 4. Print first and second 5. Repeat from i = 3 to n: a. next = first + second b. Print next c. first = second d. second = next 6. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com