Hey,
while doing an assignment I came across a code.
however, when I run it I get no output.
would like to know why if anyone knows.....
#include <stdlib.h>
#include <stdio.h>
int main(int ac, char** av) {
unsigned register int j,sum,dcnt, limit;
unsigned int number,max;
if (ac != 2) {
fprintf(stderr, "Usage: %s <number>\n", av[0]);
exit(2);
} else {
max = atoi(av[1]);
}
/* Optimization: we can skip odd numbers, these are never perfect (proof?). */
for (number = 2 ; number < max ; number += 2) {
/* Optimization: We only need to search to half the range for divisors. */
dcnt = sum = j = 0;
limit = number;
while (++j < limit) {
if (number % j == 0) {
sum += j;
dcnt++;
/* Optimization: Each time we find a divisor we get one for
free. We can then decrease the upper limit to the higher of
the divisors. */
if (number / j != number) {
sum += number / j;
limit = number / j;
dcnt++;
}
}
}
if (sum == number)
printf("%4d : perfect!\t\t%4d divisors\n", number, dcnt);
#ifndef ONLY_PERFECT
else
printf("%4d : NOT perfect\t%4d divisors\n", number, dcnt);
#endif
}
return 0;
}