#include <stdio.h>
int main(int argc, const char *argv[])
{
int first_interval;
int last_interval;
int number;
int divider;
int sum = 0;
// Define um vetor para armazer os divisores:
int dividers[10] = {0};
// Variável de controle para os divisores:
int i = 0;
printf("Enter first and last interval`s number\n"); scanf("%d %d", &first_interval
, &last_interval
);
for (number = first_interval; number >= first_interval && number <= last_interval; number++ )
{
for (divider = 1; divider < number; divider++)
{
if (number % divider == 0)
{
sum = sum + divider;
// Encontrou um divisor, então armazena-o:
dividers[i++] = divider;
}
}
if (sum == number)
{
// Número é perfeito, então exibe os divisores:
for (int j
= 0; j
< i
-1; j
++) printf("%d + ", dividers
[j
]); printf("%d = ", dividers
[i
-1]);
printf("%d PERFECT !!!\n", number
); }
// Reinicia a variável de controle:
i = 0;
sum = 0;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbihpbnQgYXJnYywgY29uc3QgY2hhciAqYXJndltdKQp7CgogIGludCBmaXJzdF9pbnRlcnZhbDsKICBpbnQgbGFzdF9pbnRlcnZhbDsKICBpbnQgbnVtYmVyOwogIGludCBkaXZpZGVyOwogIGludCBzdW0gPSAwOwogIAogIC8vIERlZmluZSB1bSB2ZXRvciBwYXJhIGFybWF6ZXIgb3MgZGl2aXNvcmVzOgogIGludCBkaXZpZGVyc1sxMF0gPSB7MH07CgogIC8vIFZhcmnDoXZlbCBkZSBjb250cm9sZSBwYXJhIG9zIGRpdmlzb3JlczoKICBpbnQgaSA9IDA7CgogIHByaW50ZigiRW50ZXIgZmlyc3QgYW5kIGxhc3QgaW50ZXJ2YWxgcyBudW1iZXJcbiIpOwogIHNjYW5mKCIlZCAlZCIsICZmaXJzdF9pbnRlcnZhbCwgJmxhc3RfaW50ZXJ2YWwpOwoKICBmb3IgKG51bWJlciA9IGZpcnN0X2ludGVydmFsOyBudW1iZXIgPj0gZmlyc3RfaW50ZXJ2YWwgJiYgbnVtYmVyIDw9IGxhc3RfaW50ZXJ2YWw7IG51bWJlcisrICkKICB7IAogICAg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