CS 159 – Spring 2011
HW #05 – 5 Points Possible
Due: March 28, 2011 at 11:00pm
Problem:
Given a range of integers, find all prime numbers in that range.
For each prime number, other than the first
and last found in the range, determine if it is a balanced, weak, or strong prime number.
A balanced prime number is one
that is equal to the average of the prime number that comes before it and the one that comes after it.
A weak prime
number is less than that average and a strong prime number is greater.
•
Do not permit the user to enter negative values for the starting range value.
•
Do not permit the user to enter an ending value that is less than the first.
◦
As with all input validation expectations, the user should be given an unlimited number of chances to meet
our input requirements.
◦
In this class we DO NOT validate data types.
You may safely assume that all input will be integers.
◦
You will NOT need a data type that can store a value larger than an
int
for this assignment.
Example Execution #1:
Enter starting range value: 0
Enter ending range value: 25
Prime numbers:
2
3 is a balanced prime.
5 is a balanced prime.
7 is a weak prime.
11 is a strong prime.
13 is a weak prime.
17 is a strong prime.
19 is a weak prime.
23
Example Execution #2:
Enter starting range value: 450
Enter ending range value: 475
Prime numbers:
457
461 is a strong prime.
463 is a weak prime.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 CRUM
 Computer Science, Natural number, Prime number, Balanced prime

Click to edit the document details