Документация
HTML CSS PHP PERL другое

Exercise: Finding Primes

 
Previous Table of Contents Next

Exercise: Finding Primes

What computer language primer would be complete without this little gem? In this exercise, you will examine a small program to find and print prime numbers. Prime numbers are divisible only by 1 and themselves; for example, 2 is prime, 3 is prime, 4 is not (because it is divisible by 1, 4, and 2), and so on. The list of primes is infinite, and they take a lot of computer power to find.

Using your text editor, type the program from Listing 3.4 and save it as Primes. Do not type in the line numbers. Make the program executable according to the instructions you learned in Hour 1.

When you're done, try running the program by typing the following at a command line:


perl -w Primes


Listing 3.4. The Co
Previous Table of Contents Next
© 2000- NIV