Menu

(Get Answer) – Write a program that includes two functions

  

Program #4

Write a program that includes two functions. The First (named isPerfect) receives no parameters and does not return any parameters. It simply calculates and prints all the perfect numbers between 1 and 10000. A perfect number is a number whose sum of its divisors (not including the number itself) add up to the number

Determine through processing and print each perfect number and its divisors from 1 to 10000 (there are only 4). Pause the screen and clear the screen between outputs. The output for each perfect number should be like the following example.

6 is perfect. Its divisors are 

1, 2, 3

The second function (named isPrime) that receives an integer as a parameter and returns a boolean that indicates whether the number is prime or not. Allow the user to enter a number between 2 and 10000 and printout whether it is prime or not. Example of prompts and output

Please enter an integer and I will tell you if it is prime: 19

19 is prime

Would you like to do another (y/n)? y

…clear screen

Please enter an integer and I will tell you if it is prime: 21

21 is not prime

Would you like to do another (y/n)? n

…end the program

Clear the screen between runs. Do not rerun the perfect code, just the prime.

Make sure you use function prototypes and no globals. Make sure your output is like the above.

Check for invalid input for the prime. If an invalid number is entered, display an error message and then go to the prompt that asks whether he wants to do another.

Name the program numbers.cpp

HTML tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *