You are on page 1of 3

Priyankar Paul 1

29SCS124

Ex. No: 6b
02/02/2011 Fibonacci Series

Aim:
To print the Fibonacci series.

Algorithm:
1. Start

2. Enter the limit as n.

3. Initialize previous = 0 and current =1.

4. Run a loop with the initial value of i as 0.

4.1. Print the value of previous.

4.2. Assign next=previous+current.

4.3. Assign previous=current

4.4. Assign current=next

5. Increment the value of i and go to step 4.1 if i is less than n.

6. Stop

Program:
Priyankar Paul 2
29SCS124

print"Enter the limit: ";


$n=<STDIN>;
print"The Fibonacci Series is as follows: \n";
$a=0;
$b=1;
print "$a\n";
print "$b\n";
for($i=0;$i<$n;$i++)
{
$c=$a+$b;
print "$c\n";
$a=$b;
$b=$c;
}

Output:
Priyankar Paul 3
29SCS124

Enter the limit: 10


The Fibonacci Series is as follows:
0
1
1
2
3
5
8
13
21
34
55
89

Result:

Thus the PERL program to print the fibonacci series was successfully executed and its output
was verified.

You might also like