Friday 22 November 2013

PERL : Fibonacci Series


Fibonacci Series :

The below code explains the Fibonacci series in PERL programming language :

use warnings;
use strict;

my $f1=0;
my $f2=1;
my ( $n, $i, $f3 ) ;

print "\n*** FIBONACCI SERIES ***\n";
chomp ( $n = <STDIN> ) ;

printf ("$f1\t$f2") ;

for ( $i = 0 ; $i<$n-2 ; $i++ )
{
         $f3 = $f1+$f2 ;
         $f1 = $f2 ;
         $f2 = $f3 ;
         printf ("\t$f3");
}

Output :

1
1
2
3
5
8
13

To know about the Fibonacci Series in detail and also to know the codes of the Fibonacci Series in various other programming languages Click Here

If the above link doesn't work go to this URL :

No comments:

Post a Comment