Advertisement
Militsa

11.Fibonacci Sequence

Jan 3rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>First Steps Into PHP</title>
  6.  
  7. </head>
  8. <body>
  9. <form>
  10.     N: <input type="text" name="num" />
  11.     <input type="submit" />
  12. </form>
  13. <!--Write your PHP Script here-->
  14. <?php
  15. if(isset($_GET['num'])) {
  16.     $num = intval($_GET['num']);
  17.     if($num == 1) {
  18.         echo 1;
  19.     } else if($num == 2) {
  20.         echo 1 . " " . 1 . " ";
  21.     } else {
  22.         echo 1 . " " . 1 . " ";
  23.         $a = 1;
  24.         $b = 1;
  25.         for($i = 2; $i <$num; $i++) {
  26.             $c = $a + $b;
  27.             $a = $b;
  28.             $b = $c;
  29.             echo $c . " ";
  30.         }
  31.     }
  32. }
  33. ?>
  34. </body>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement