usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Simple Code for Listing Even Numbers in Perl - Fun Exercise for Young Students



What are Even Numbers?

Hello pupils, what are even numbers?
Answer:
Even numbers are numbers that are divisible by 2.

They include:

2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, ...

Considering how simple and straight-forward even numbers are, writing a Perl code for even numbers serves as a great way to introduce our Mathematics educational activities for young learners.
Well then, let's see how we can write a programming code to make our computer list a set of even numbers in the Perl language, between a given range of values. Bear in mind, we use only a loop and a simple conditional statement for the Perl code.

Create a new Perl Class File; call it Arithmetic.pl.
Create a new Perl Module File; call it evenNumbers.pm.

Type out the adjoining Perl code that list even numbers.



How to run Perl Codes

Run the code from the cmd shell with the command: cd ~/Documents/usingMaths -- to navigate to the folder where you saved your files;
perl Arithmetic.pl









<< PreviousNext >>