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