Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define UPPERLIMIT 30
  4.  
  5. int CountDivisors(int);
  6.  
  7. int main()
  8. {
  9.  
  10.     FILE *file;
  11.     char *filename = "C:\\Users\\chris\\My Documents\\divisorsraw.txt";
  12.     int index, divisors = 0;
  13.     int largest[2] = {0,0}; //{number,divisors}
  14.  
  15.     file = fopen(filename,"w");
  16.     if (file == NULL)
  17.     {
  18.         printf("File could not be open\n");
  19.         return 0;
  20.     }
  21.  
  22.     for (index = 1; index <= UPPERLIMIT; index++)
  23.     {
  24.         divisors = RecursiveCountDivisors(index);
  25.         if (divisors > largest[1])
  26.         {
  27.             largest[0] = index;
  28.             largest[1] = divisors;
  29.         }
  30.         fprintf(file, "%i\n", divisors);
  31.         printf("%i has %i divisors\n", index, divisors);
  32.     }
  33.     printf("The largest is %i with %i divisors\n",largest[0], largest[1]);
  34.     fclose(file);
  35.     return 0;
  36. }
  37.  
  38. int CountDivisors(int n)
  39. {
  40.     int x, count = 0;
  41.     for (x = 1; x <= n; x++)
  42.     {
  43.         if ((n % x) == 0)
  44.         {
  45.             count++;
  46.         }
  47.     }
  48.     return count;
  49. }