2
I am learning programming in C online and wrote this code to find the perfect numbers in a given range, but I would like to show the result with the sum of the divisors, for example :
1 + 2 + 3 = 6 PERFECT !!!
1 + 2 + 4 + 7 + 14 = 28 PERFECT !!!
My code is like this :
#include <stdio.h>
int main(int argc, const char * argv[]) {
int first_interval;
int last_interval;
int number;
int divider;
int sum = 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;
}
}
if (sum == number) {
printf("%d = %d PERFECT !!!\n", number, sum);
}
sum = 0;
}
return 0;
}
How can I get the desired result, does anyone have any idea?
Thank you Anderson, I have not yet arrived in vectors, but I will already search how to use them (would be array in English ? ).
– Jose Marcio
Yes, it would be the equivalent of array in English.
– Woss