Advertisement
paperline27

menghasilkan.deret.fibonacci.pl

Feb 25th, 2024
1,490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.31 KB | Source Code | 0 0
  1. sub fibonacci {
  2.     my $n = shift;
  3.     return $n if $n <= 1;
  4.     return fibonacci($n - 1) + fibonacci($n - 2);
  5. }
  6.  
  7. print "Masukkan panjang deret Fibonacci: ";
  8. my $panjang = <STDIN>;
  9. chomp($panjang);
  10.  
  11. print "Deret Fibonacci: ";
  12. for (my $i = 0; $i < $panjang; $i++) {
  13.     print fibonacci($i), " ";
  14. }
  15. print "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement