Question
///// I neen help with this program . It has to be done in C++ and strictly follow the instractions.///// A prime number is a
///// I neen help with this program . It has to be done in C++ and strictly follow the instractions./////
A prime number is a positive integer that has no integer divisors other than 1 and itself.
A perfect number is a positive integer p such that p = s(n) where s(n) is the sum of all proper divisors of p. A proper divisor of a number p is a divisor other than p. Examples: 6 and 28 are perfect numbers: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14
A triangular number is a number obtained by adding all positive integers less than or equal to a given positive integer n. Example: 10 is a triangular number: 10 = 1 + 2 + 3 + 4
The factorial of an integer ( non-negative) n is the product of all positive integers from 1 to n. Note: the factorial of 0 is 1. Example: 6 is the factorial of 3 ( 3*2*1 = 6 )
Write a C++ program that will display interesting facts about a number chosen by the user. Do your printing in the main program.
The program will repeatedly prompt the user to enter an integer and it will display information about the integer.
Display a message for each of the following possible facts:
The number is prime or the number is not prime
The number is a perfect number
The number is a triangular number
The number is a factorial of a non-negative integer n
Let the user continue for as long as he/she wishes. Do your printing on the screen AND in a file called Facts About Numbers.
You should have the following functions:
1) A recursive function called isPrime that determines if a number passed as a parameter is a prime number. The function should return true if the parameter is a prime number, false otherwise.
2) A function called isPerfect that determines if a number passed as a parameter is a perfect number. The function should return true if the parameter is a perfect number, false otherwise. The function isPerfect should call a recursive function sumOfDivisors to find the sum of all proper divisors of the parameter.
3) A recursive function called isTriangular that determines if a number passed as a parameter is a triangular number. The function should return true if the parameter is a triangular number, false otherwise.
4) A recursive function called isFactorial that determines if a number passed as a parameter is a factorial of a non-negative integer. The function should return -1 if it is not a factorial of any integer or the integer it is the factorial of.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started