Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void show_perfect_number(int a, int b) {
- int n = 0; // сумма делителей
- for (int i = a; i <= b; i++) {
- for (int j = 1; j < i; j++) {
- if (i % j == 0) { // нашли делитель
- n += j;
- }
- }
- if (i == n) { // число является совершенным
- cout << i << " ";
- }
- n = 0; // обнулить переменную для суммы
- }
- }
- int main() {
- setlocale(LC_ALL, "ru");
- show_perfect_number(1, 10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement