Question: Write a program in c++ that asks the user for input for two integer values: startval, and endval. The program will then find all Perfect
Write a program in c++ that asks the user for input for two integer values: startval, and endval. The program will then find all Perfect Numbers that fall between startval and endval. A perfect number is a number equal to the sum of all its proper divisors (divisors smaller than the number) including 1. The number 6 is the smallest perfect number; because it is the sum of its divisors 1, 2, and 3 (1+2+3 = 6). The next perfect number is 28 (28 = 1+2+4+7+14). The search for the Perfect Number will require two loops (nested). The outer loop will step thru the range of numbers between startval and endval. The inner loop will step thru the values from 1 to (outerval/2) to determine the factors of the number.
Write and use a function called isAFactor that accepts two int args, and determines if the second number is a factor of the first. It should return a bool value.
When a number is found, print out a message:
X is a Perfect Number.
If no Perfect Numbers can be found in the given range, print the message:
No Perfect Numbers found between x and y
.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
