Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- bool isPerfect(int num)
- {
- int sum{0};
- for (int div{ 1 }; div < num; ++div)
- {
- if (num % div == 0)
- {
- sum += div;
- }
- }
- return sum == num;
- }
- void printPerfectRange(int begin, int end)
- {
- int copy;
- if (begin > end) { copy = begin; begin = end; end = copy; }
- for (; begin != end; ++begin)
- {
- if (isPerfect(begin)) { std::cout << begin << '\n'; }
- }
- }
- int main()
- {
- printPerfectRange(1, 10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement