A positive integer number n is said to be perfect if it is equal to the sum of its proper
divisors. In other words, n is equal to the sum of its positive divisors excluding itself. For
example, 6 and 28 are perfect numbers. Indeed, we have:
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
Assume that the input contains a sequence of integers, each of which could be negative,
positive, or equal to zero. Moreover, this sequence ends with the integer ā€“1.
2

1. Write a C++ program that reads a sequence of integers and saves it into an array. Your
program has to check whether each integer n in the sequence is perfect using a brute
force approach. That is, your program should use all possible divisors of n from 2 to nā€“1.

2. Is it possible to optimize the above C++ program? Explain your answer

Recommended Answers

All 2 Replies

First read this and this, then post your effort.

This also goes for your other thread, which also is called "C++ program help" :icon_frown:

That is just an assignment. How far have you gotten? Any thoughts on how to solve the exercise?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.