Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 50000
  4.  
  5. int CountDivisors(int);
  6. int TriangleNumber(int);
  7.  
  8. int main()
  9. {
  10.  
  11.     int i;
  12.     for(i = 0; i <= MAX; i++)
  13.     {
  14.         int TN = TriangleNumber(i);
  15.         int TNDIV = CountDivisors(TN);
  16.  
  17.         if (TNDIV > 500)
  18.         {
  19.             printf("Triangle Number %i is %i and has %i divisors\n", i, TN, TNDIV);
  20.             break;
  21.         }
  22.     }
  23.     return 0;
  24. }
  25.  
  26. int CountDivisors(int n)
  27. {
  28.     int x, count = 0;
  29.     for (x = 1; x <= n; x++)
  30.     {
  31.         if ((n % x) == 0)
  32.         {
  33.             count++;
  34.         }
  35.     }
  36.     return count;
  37. }
  38.  
  39. int TriangleNumber(int n)
  40. {
  41.     int x, sum = 0;
  42.     for (x = 1; x <= n; x++)
  43.     {
  44.         sum += x;
  45.     }
  46.     return sum;
  47. }
  48.  
  49.  
  50.