Question: A positive integer is a prime number if its only positive integer divisors are itself and 1. Write a program to determine whether or not

A positive integer is a prime number if its only positive integer divisors are itself and 1. Write a program to determine whether or not a given integer is prime. The program should contain two functions:

main: to ask the user for a positive integer and to print the result

isPrime: to determine whether the user's input is prime by testing all possible divisors. This function should return two values:

variable_1: a Boolean value indicating whether the number is prime or not

variable_2: a numeric value indicating either the first divisor found (if the number is not prime) or the number of divisors tried (if the number is prime)

Note that the main function needs to print either of two rather different looking output messages depending on the results returned from the isPrime function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!