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;
}``````

Because this is a code which accepts [search]command line arguments[/search]. You need to run it using a console window by supplying parameters at the command line.

If you using windows you can invoke it by opening the command prompt, going to the location where the executable of the program resides ( .exe file ) and typing this;

c:\Path_to_your_exe\program_name 12 <-- any number you want

This should do the trick.

Hope it helped, bye.

did you enter a number as argument to the program? Such as:

c:>myprog 15 <Enter>