Sequences Program
Background:
An arithmetic sequence is a
set of elements ordered in some specific way (eg, {2, 5, 8, 11, 14, ...}) in
which there is a common difference between successive terms. As in the example
above, where 3 is the common difference. Each successive term of the arithmetic
sequence is found by adding the common difference to the preceding term.
(Source = http://www.csdsac.org/Curriculum/mathglossary.htm)
Basic Program:
Write a program that allows
the user to view arithmetic sequences.
In the basic version, you should allow the user to pick the difference
between terms. The sequence always starts
with the number 1 and ends when the sequence gets above 100.
Example – The user chooses
a difference of 12:
1, 13, 25, 37, 49, 61, 73,
85, 97, 109
(Format your output so that
a comma separates the elements. It’s a
little tricky to print commas between every number, but not after the last
one.)
Extension #1:
Try running your program
with a difference of zero or less. You
should notice that entering zero or a negative number causes your program to
become stuck in an infinite loop. Good
programmers don’t allow their programs to crash or get stuck like this.
Use a data validation loop
to ensure that the user enters a number greater than zero. A data validation loop makes the user enter
data until it fits valid criteria.
Extension #2:
After the user has seen one
sequence, ask them if they would like to see another. Allow them to enter y/n and react accordingly. Account for uppercase or lowercase
letters. (Entering Y is the same as
entering y)
Extension #3:
Instead of running
sequences from 1 to 100, allow the user to pick their starting number and limit
as well. Again, use data validation to
ensure that the staring point is not greater than the limit.