Wednesday, October 19, 2022

Fibonacci sequence in perl

 

#the variable $range contains the number uptil which you need to calculate the fibonacci sequence
# $range is available to you here

$ans = "xyz"; #return the correct string

#write your code for genersting fibonacci sequence here
$i=0,$j=1;
$ans=$i." ".$j;
while(($range-2)>0)
{
$ans=$ans." ".($i+$j);

$j=$i+$j;
$i=$j-$i;
$range--;

}
return $ans;

No comments:

Post a Comment