Question

An integer number is said to be a perfect number if its factors, including 1 (but...

An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number, because 6 = 1+2+3. Write a method isPerfect that determines if parameter number is a perfect number. Use this method in a test program to display all the perfect numbers between 1 and 1000. Display the factors of each perfect number to confirm that the number is indeed perfect.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, there are 4 perfect numbers between 1 and 1000. here is the code and the output of all the 4 perfect numbers and its factor.

Let me know for any help with any other questions.


Thank You !
===========================================================================


public class PerfectNum {

    public static boolean isPefect(int num) {

        int factorTotal = 0;
        for (int factor = 1; factor <= (num + 1) / 2; factor++) {
            if (num % factor == 0) factorTotal += factor;
        }
        return factorTotal == num;
    }

    public static void main(String[] args) {

        for (int num = 1; num <= 1000; num++) {
            if (isPefect(num)) {

                System.out.print("Perfect Number: " + num + " =  Factors ( ");
                for (int factor = 1; factor <= (num + 1) / 2; factor++) {
                    if (num % factor == 0)
                        System.out.print(factor + " ");
                }
                System.out.println(") ");
            }

        }

    }
}

======================================================================

Add a comment
Know the answer?
Add Answer to:
An integer number is said to be a perfect number if its factors, including 1 (but...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the C Programming Language: An integer number is said to be a perfect number if...

    Using the C Programming Language: An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each...

  • An integer number is said to be a perfect number if it is equal to the...

    An integer number is said to be a perfect number if it is equal to the sum of its factors (divisors), including 1 (but not the number itself). For example, 6 is a perfect number because 6 = 3+2+1. Write a C function isPerfect that returns true if the input integer number is a perfect number and false otherwise. Then, use this function in a C program that determines and prints all the perfect numbers between 1 and 1000.

  • Question 3 (10 marks) An integer number is said to be a perfect number if its...

    Question 3 (10 marks) An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because its factors, except itself, are 3, 2, and 1, and 6 = 3+2+1, but 12 is not a perfect number because its factors, except itself, are 6, 4, 3, 2, and 1, but 12 # 6+4+3+2+1. First. Write a C function, called isperfect, that...

  • An integer is said to be a perfect number if the sum of its divisors, including...

    An integer is said to be a perfect number if the sum of its divisors, including 1(but not the number itself), is equal to the number. For example, 6 is a perfect number because 6 = 1+2+3. A) Write a function numPerfect( number ) that returns true when the number is a perfect number, false when it is not.        B) Write a C# console program that calls the function in A) to determine and print all the perfect numbers...

  • it should be written in c or c++ program Question 1 (25 points) An integer number...

    it should be written in c or c++ program Question 1 (25 points) An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 -1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1...

  • 1. An integer is said to be perfect if the sum of its factors, including 1,...

    1. An integer is said to be perfect if the sum of its factors, including 1, is equal to the number itself. Write a Prolog predicate perfect(N, F), which determines if integer N is perfect and if so, return it’s list of factors F. If N is not perfect, the predicate fails. You may find the arithmetic operation M mod N to be useful. Test your predicate on the following. • perfect(6, Factors) ⇒ Factors = [1, 2, 3] •...

  • For C++: A perfect number has these properties 1) positive integer 2) the sum of its...

    For C++: A perfect number has these properties 1) positive integer 2) the sum of its proper divisors is the number itself 6 and 28 are perfect numbers Write two functions that return true if its value parameter is a perfect number and false if its value parameter is not a perfect numbers. The two function look like bool isPerfect(int) and void isPerfect(int, bool&) If you want more perfect number you find them on the Internet.

  • A perfect number is a positive integer that is equal to the sum of its (proper)...

    A perfect number is a positive integer that is equal to the sum of its (proper) positive divisors, including 1 but excluding itself. A divisor of a number is one which divides the number evenly (i.e., without a remainder). For example, consider number 6. Its divisors are 1, 2, 3, and 6. Since we do not include number itself, we only have 1, 2, and 3. Because the sum of these divisors of 6 is 6, i.e., 1 + 2...

  • A perfect number is a positive integer that equals the sum of all of its divisors...

    A perfect number is a positive integer that equals the sum of all of its divisors (including the divisor 1 but excluding the number itself). For example 6, 28 and 496 are perfect numbers because 6=1+2+3 28 1 + 2 + 4 + 7 + 14 496 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 Write a program to read a positive integer value, N, and find the smallest perfect number...

  • A positive integer is said to be a perfect number if it equals the sum of...

    A positive integer is said to be a perfect number if it equals the sum of its positive divisors (excluding the number itself). As an example, 6 is aperfect number because its divisors, 1, 2, and 3 sum up to 6. The first four perfect numbers are 6, 28, 496, 8128. Write a C program that asks the user to enter a number and checks if the number is perfect. Your program should run interactively until the user quits. Try...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT