GENERAL DESCRIPTION

A prime number is an integer greater than 1 whose only integer factors are 1 and itself. A right-truncatable prime number (or right-prime number) is a prime number that remains prime as each of its rightmost digits is removed. For example, consider the value 719. 719 is prime, 71 is prime, and 7 is prime. Thus, 719 is a right-prime number.

Alternatively, consider the value 97. Although 97 is prime, 9 is not. Thus, 97 is not a right-prime number. (Source: The Prime Pages, http://www.utm.edu/research/primes/).

In order to receive any credit on this program, you must provide a detailed, correct algorithm. This algorithm will be judged more critically than the previous algorithm. If you are still unsure about writing algorithms, you may use the example given on pages 73 - 75 in your textbook as a guideline. As in that example, your algorithm should indicate where in your program you will use loops, where you will use decision statements, and what computations you will make.

The input to the program is a single integer y. The input value may be any number between 2 and 231-1 ( 2,147,483,647), inclusive. Given an input value y, write a program that determines if y is right-prime.

Your program should produce exactly one line of text as output which indicates whether y is a right-prime. The main function should input the value from stdin and output the text to stdout.

The conversion from input to output should be performed in a different function called isRightPrime. This function should accept an integer parameter which will be the value to test to see if it is right-prime. In addition, this function should return an integer value that equals 1 if the number is right-prime and 0 if it is not right-prime. This function will need the ability to determine if successive values are prime, so it should call the isPrime function described below.

The isPrime function should accept an integer parameter, x, which will be the value to test to see if it is prime. In addition, this function should return an integer value that equals 1 if x is prime and 0 if x is not prime to isRightPrime.

## Recommended Answers

Jump to PostNice Copy/Paste job. Why don't you show us how to do this?

You must know something about writing a program. Start by writing a program that determines if a number is prime. Then, expand its capabilities.

Here's a start:

`#include <iostream> using std::cout; using …`

Jump to PostWell, how about reading in the input and passing it to rightPrime. Make isPrime just return 1. Make rightPrime just call isPrime and return the value. Then harness that return in main and display a result. That gives you a skeleton. Then write isPrime and get it working. Then write …

Jump to PostRight off the bat, these don't match the spec:

`double isRightPrime(); double isPrime();`

Read the spec carefully and make them match. What are they supposed to return? What do they take as parameters?

## All 10 Replies

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.