Find 1000 Prime Numbers - Sharp MZ-80A Owner's Manual

Hide thumbs Also See for MZ-80A:
Table of Contents

Advertisement

100
Find
1000
prime numbers
Introduction
to
methodological study of programming
[2]
It is essential
to always keep the objective and the
procedure
for accomplishing
it in
mind when formulating a pro¬
gram. Most programmers,
however,
are seldom
conscious of this problem and
create
complicated, inscrutable programs
in
their own style. Frequently, such programs can hardly be understood even
by those who wrote them,
much less
by
others.
Such problems arise because the programmer does
not
clarify the relationship beteen the structure of the problem
and the algorithm for solving
it when
the program is
written.
Consideration of this problem has led
to active
methodo¬
logical study
of
programming
itself. E.W.
Dijkstra is
one
of
the leaders in this field, and has
written
many outstanding
books on this subject. In one of these
booksf, he
introduced his own
idea about programming (called
structured pro¬
gramming), using the problem
of finding
prime numbers
as an example. In this
section,
we
briefly explain his
concepts
using the
same
problem.
Problem:
Print 1000 prime numbers 2,3,5,7,11
.....
i n increasing order
of magnitude.
Approach
to
the problem
,
Many different, programs could be
used
to
solve this problem. The
first
major proposition, however, is that the
program constructed must be a practical
one.
An extreme approach might be as
follows.
"Find and print prime numbers starting
at
the smallest one? 2 is the smallest
prime number, so,
let's
print
2 first.
Next is
3, next is 5, next is
7. All
we have
to do is to print them using the
PRINT
statement.
..."
This
is not, however,
an
efficient method of
using the
BASIC interpreter, and
cannot truly be regarded
as program¬
ming.
According to
Dijkstra, many decisions
must be made
until a program is completed. We should make such decisions
only when they are actually required, rather than making them without discipline. In other
words,
programming should
be conducted in
stages.
The
first
decision to
be made in
our
problem is whether the
1000
prime
numbers are
to
be
found first,
then printed
all
at
once,
or whether they
are
to
be printed
as
they
are found.
By deciding on the
former method,
we place the
program in perspective
as follows.
GOSUB
"Find 1000
prime
numbers."
GOSUB "Print all numbers found."
END
Find 1000 prime numbers.
--
-
Subroutines
Print all numbers found.
I
J
Main program
t)
Dijkstra,
Hoar.
Dahr: Structured Programming,
1969 ALGOL
is used
as
the programming language in this publication.

Advertisement

Table of Contents
loading

Table of Contents