Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Happy Prime Number Program A happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit.

Happy Prime Number Program

A happy number is a number which eventually reaches 1 when replaced by the sum of the square of each digit. Prime numbers are numbers that have only 2 factors: 1 and themselves.10-happy prime numbers are happy prime numbers that use the familiar base 10 numbers. A happy prime is both a happy number, and prime. Not all happy numbers are prime, and not all primes are happy numbers.

This program will be used to explore the distance between 10-happy primes on the number line. The program should begin by printing out to the screen a concise explanation of what a 10-happy prime is. The program will continue by asking the interactive user for an integer between 1 and 1,000,000 inclusive. If the user fails to enter a legal integer in the specified range, reprompt until the user succeeds. I will call the legal number entered X. X will form the lower bound of your search for 10-happy primes.

Next, go through a similar process to get the upper bound (Lets call it Y) of your search, an integer larger than X, but smaller than 1,000,001 inclusive. Once X and Y are set, your program finds all the happy primes between X and Y (inclusive). There are different possible scenarios:

Scenario A: There are no 10-happy primes between X and Y inclusive. In this case, your program announces that fact, and halts.

Scenario B: If there is only one 10-happy prime between X and Y inclusive, the program should report this situation and the happy prime to the user, and halt.

Scenario C: If there are only two 10-happy primes between X and Y inclusive, the program should say so, list the two 10-happy primes, report how many integers occur between the two 10-happy primes, and then halt.

Scenario D: In the case where there are 3 or more 10-happy primes between X and Y inclusive, the program should print out all the 10-happy primes in the range, and then calculate all the gaps between all the 10-happy primes between X and Y inclusive. The gap is the number of integers that are NOT 10-happy primes between a 10-happy prime H1 and the next higher 10-happy prime H2. (Be careful. This is different from the difference between the two numbers.) There are always N-1 gaps between N 10-happy primes. Once all the gaps are determined, your program should announce how many gaps there are, and print out a list of all the gap sizes. Next, your program should report the average gap, the smallest gap, the largest gap, and the median gap. These values should be labeled well when displayed. After displaying all of these values, the program should halt.

The program is required to have at least two separate sub-programs (usually called either a function or a procedure, depending on what language you use). One subprogram should take an integer as a parameter, and the subprogram should return True if the integer is a happy number, and False if the integer is not happy. The second required subprogram also takes a single integer as a parameter, and returns True if the integer is a prime, and returns False if the integer is not prime. Document each subprogram appropriately. We will look for each of these subprograms in your program, and you will lose points if we dont find them.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

Students also viewed these Databases questions