Yeah, I didn't implement all the fixes you suggested yet. I just modified this thing and here it is
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main(int argc, char** argv) {
clock_t start = clock();
int limit, n1, n2, chk;
int counter = 220;
printf("Enter limit:\n");
if (scanf("%d", &limit)!=1 || limit<=0)
{
printf("Invalid input.");
return 0;
}
else
{
while (counter < limit)
{
int sum = 0;
int div = 0;
counter++;
int stop = (int) sqrt(counter);
while (div <= stop)
{
++div;
if (counter % div == 0)
sum += div;
}
chk = sum;
sum = div = 0;
while (div <= chk/2)
{
++div;
if (chk % div == 0)
sum += div;
}
if (sum == counter)
{
if (counter == chk) continue;
n1 = counter;
if (n1 == n2) continue;
n2 = chk;
printf("%d, %d\n",n1,n2);
}
}
}
printf("Time elapsed: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);
return 0;
}