Hi I have been getting a runtime "debug error" when I run the code below. The error occurs at the delete [] div. I have been trying multiple ways to get this to work in C++ without using vectors or anything of that sort. Any help with figuring out why this is happening, and a possible solution would really be great! Thanks
Code:
int addDivisors(int* arr)
{
int index = 0;
int sum = 0;
while(arr[index] != -1)
{
sum += arr[index];
index++;
}
return sum;
}
int* getDivisors(_int64 num)
{
int x = divisors(num);
int* divisors = new int[x];
int count = 0;
for(int i=1; i<=num; i++)
{
if(num % i == 0)
{
divisors[count]=i;
count++;
}
}
divisors[count] = -1;
return divisors;
}
int euler21()
{
int MAX = 10000;
int a[10000];
int b[10000];
for(_int64 i=1;i<MAX;i++)
{
int* div = 0;
div = getDivisors(i);
int sum = addDivisors(div);
a[i-1] = b[i-1] = sum;
delete [] div;
div = NULL;
}
return 0;
}