Hello guys. My task is to find the first n natural numbers that have more divisors than any other natural number before them for a given n. So basicly if n=5, then the program have to print 1,2,4,6,12. I made it work but now my problem is that my program works only to n=28,29 because the numbers seems to get quite large. For some reason i cannot make my k bigger than 99999 because then something breaks and i cannot fix it. Is there a way to make this work for any given n, or at least for more than 29.
Code:
#include <stdio.h>
#include <stdlib.h>
int FindDevisors(int n)
{
int i,j=0;
for (i=1;i<=n;i++)
{
if (n%i==0)
{
j++;
}
}
return j;
}
int main()
{
int n,i,j,k,br=0,brc;
printf("Enter n ");
scanf("%d", &n);
k=99999;
int answer[n];
int numbers[k];
//int *current;
//current = (int*)malloc(n * sizeof(int));
int current[k];
for(i=0,j=0;i<=k,j<=n;i++)
{
current[i]=FindDevisors(i);
if(br<current[i])
{
for(brc=0;brc<i;brc++)
{
numbers[j]=i;
}
br=current[i];
answer[j]=current[i];
j++;
}
//printf("Devisors of %d are : %d\n",i,current[i]);
}
for(i=0;i<n;i++)
{
printf("\n Answer %d = %d and have %d devisors ",i+1,numbers[i], answer[i]);
}
return 0;
}