Answer the question
In order to leave comments, you need to log in
Why is the result of the function execution incorrect?
A number is called perfect if the sum of all its divisors is equal to itself. You need to write a search for such numbers in the entered interval.
int a, b;
cin >> a >> b;
printf("Perfect numbers of range [%d;%d]:\n", a, b);
for (int i = a; i <= b; i++)//перебор всех чисел в интервале
{
int sum = 0;//при каждом новом числе сумма обнуляется
for (int j = 2; j < abs(i); j++)
if (abs(i) % j == 0)//делитель - число, которое делит первичное число без остатка
{
sum += j;
}
if (sum == i)
cout << i << '\t';
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question