Question

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

  1. 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 between 1 and 2000. Print the divisors of each perfect number to confirm that the number is indeed perfect.

      C) Use the function in A) to determine and display how many perfect numbers there are between 5 and 5000.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

using System;

class MainClass {

public static bool numPerfect(int number) {

int sum = 0;

//Console.Write("Divisors of " + number + " are : ");

for (int i = 1; i < number;i++) {

if (number % i == 0) {

sum = sum + i;

//Console.Write(i + " ");

}

}

//Console.WriteLine();

return sum == number;

}

public static void Main (string[] args) {

Console.Write("The Perfect numbers within the range 1 and 2000 : \n");

for (int i=1; i<=2000; i++) {

if (numPerfect(i)) {

Console.Write(i + " ");

}

}

int count = 0;

for (int i=5; i<=500; i++) {

if (numPerfect(i)) {

count ++;

}

}

Console.Write("\n\nCount of Perfect numbers within the range 5 and 5000 : " + count);

}

}

Add a comment
Know the answer?
Add Answer to:
An integer is said to be a perfect number if the sum of its divisors, including...
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
  • 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.

  • 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...

  • 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 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...

  • 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...

  • 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...

  • 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...

  • 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.

  • 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] •...

  • Please Write the task in c++ Task A perfect number is an integer that is equal...

    Please Write the task in c++ Task A perfect number is an integer that is equal to the sum of its divisors (where 1 is considered a divisor). For example, 6 is perfect because its divisors are 1, 2, and 3, and 1 + 2 + 3 is 6. Similarly, 28 is perfect because it equals 1 + 2 + 4 + 7 + 14. A quite good number is an integer whose badness—the size of the difference between the...

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