Advertisement
dederusliandi

TEST CASE 3 JATIS

May 26th, 2022
604
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $x = 2;
  3. $y = 3;
  4. $n = 3;
  5. function fibonacci($number){
  6.     if ($number == 0) {
  7.         return 0;
  8.     } else if ($number == 1) {
  9.         return 1;
  10.     } else {
  11.         return fibonacci($number-1) + fibonacci($number-2);
  12.     }
  13. }
  14. $fibo_even = [];
  15. $fibo_odd = [];
  16. $number = 0;
  17. $fibonumber = 0;
  18. while (count($fibo_even) + count($fibo_odd) < $n) {
  19.     $fibonumber = fibonacci($number);
  20.     $number++;
  21.  
  22.     if ($fibonumber >= $x || $fibonumber >= $y) {
  23.         if ($fibonumber % 2 == 0) {
  24.             array_push($fibo_even, $fibonumber);
  25.         } else {
  26.             array_push($fibo_odd, $fibonumber);
  27.         }
  28.         echo $fibonumber . " ";
  29.     }
  30. }
  31. $output1 = "\nSum of even " . array_sum($fibo_even);
  32. $output2 = "\nSum of odd " . array_sum($fibo_odd);
  33.  
  34. echo $output1;
  35. echo $output2;
  36. ?>
  37.  
Advertisement
RAW Paste Data Copied
Advertisement