# Thread: Finding Abundant Numbers from txt file

1. ## Finding Abundant Numbers from txt file

I have to Write a program that reads in a list of numbers from a file, and for each number, determines and prints out whether or not that number is abundant.

Ive got this code so far...i cant get it to work. I just put randon numbers in the txt file

Code:
```      #include <stdio.h>

int main(void){

FILE *ifp= fopen("abundant.txt", "r");

int numcases;

int i;

int j;

int num;

int divisor; // this will be used to calculate the sum of the divisors

int sum =0;

fscanf(ifp, "%d", &numcases);

for (i=1; i<= numcases; i++){

for (j=1; j <= (num/2); j++)

fscanf(ifp, "%d", &num);

divisor = num % j;

if (divisor == 0)

sum= sum+j;

}

fclose(ifp);

if (sum > num)

printf("Test Case #%d: %d is an abundant number.\n", numcases, num);

else printf("Test Case #%d: %d is not an abundant numnber.\n", numcases, num);

system("pause");

return 0;

}```

2. What do you mean by an "abundant number"

3. numbers with proper divisors that sum to greater than the number itself. These numbers are called, “abundant numbers.” A proper divisor of a number is any number strictly less than it that divides evenly into it. For example, 6 is a proper divisor of 12, but 12 is not. 12 is an example of an abundant number because 1+2+3+4+6 = 16 and 16 is greater than 12. As this example shows, one way to find out all the proper divisors of a number is to try each integer (starting at 1) out until you reach the number divided by 2. (It’s impossible for any number in between 7 and 11 to divide evenly into 12 because it is guaranteed that the result of the division is less than 2 since we are dividing by a greater number, and greater than 1, since we are not dividing by the number itself.)

4. First, have you checked that you're getting the numbers written out, and read in OK?

Second, numcases means what? That should be testcase or testnum or something else for a variable name. It should not control the stop on the for loop.

Third, you're using num/2 as a stop control for the j loop, but num/2 was never given a value. Global numbers will be set to zero, but local int's - probably not. Check that.