Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define UPPERLIMIT 30
- int CountDivisors(int);
- int main()
- {
- FILE *file;
- char *filename = "C:\\Users\\chris\\My Documents\\divisorsraw.txt";
- int index, divisors = 0;
- int largest[2] = {0,0}; //{number,divisors}
- file = fopen(filename,"w");
- if (file == NULL)
- {
- printf("File could not be open\n");
- return 0;
- }
- for (index = 1; index <= UPPERLIMIT; index++)
- {
- divisors = RecursiveCountDivisors(index);
- if (divisors > largest[1])
- {
- largest[0] = index;
- largest[1] = divisors;
- }
- fprintf(file, "%i\n", divisors);
- printf("%i has %i divisors\n", index, divisors);
- }
- printf("The largest is %i with %i divisors\n",largest[0], largest[1]);
- fclose(file);
- return 0;
- }
- int CountDivisors(int n)
- {
- int x, count = 0;
- for (x = 1; x <= n; x++)
- {
- if ((n % x) == 0)
- {
- count++;
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement