Skip to content

Commit c8f8df2

Browse files
authored
Create NthFibonacci.pl
Perl script for generating nth term of Fibonacci series
1 parent aa95f46 commit c8f8df2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

NthFibonacci/NthFibonacci.pl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/perl -w
2+
3+
4+
my ($a, $b, $fib) = (1, 0, 0);
5+
6+
print "Enter the number of term to be printed: ";
7+
chomp($range = <STDIN>);
8+
9+
my $iterator = 0;
10+
while ($iterator < $range) {
11+
$fib = $a + $b;
12+
$a = $b;
13+
$b = $fib;
14+
$iterator++;
15+
}
16+
17+
print "Output: $fib";

0 commit comments

Comments
 (0)