Saturday, May 31, 2014

List numbers in a specific range

Script

#!/usr/bin/perl

print ("Enter the starting number: ");
$start = <STDIN>;
chop ($start);
print ("Enter the last number: ");
$last = <STDIN>;
chop ($last);

@list = ($start..$last);
$count = 0;

print ("Here is the list: \n");

while ($list [$count] != 0 || $list [$count] == -1 || $list [$count + 1] ==1 )
{
        print ("$list[$count] \n");
        $count++;
}

Execution



Enter the starting number: -20
Enter the last number: 17
Here is the list:
-20
-19
-18
-17
-16
-15
-14
-13
-12
-11
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

No comments:

Post a Comment