Untitled
unknown
plain_text
2 years ago
681 B
17
Indexable
#include <stdio.h>
int main()
{
unsigned int num;
scanf("%u",&num);
for (unsigned int j = num ; j > 0 ; j--)
{
// defining variables
unsigned int sum = 0;
// loop to get all proper divisors
// it is sufficient to loop until num/2, because after that there will not be other proper divisors!
for (int i = 1; i <= j / 2; i++)
{
if (j % i == 0) // if the number can be divided by the current divisor 'i'
sum += i; // then add 'i' to the running sum
}
// at the end of the loop, check if num is equal to sum
if (j == sum)
printf("%u\n",j);
}
}
Editor is loading...
Leave a Comment