I have a question about debug\ release mode in visual studio.
I wrote a recursive program that gets an array of integers (maximum size of 20 cells) and rearrange it by that rules:
The first numbers are prime numbers, after that (non prime numbers), numbers which divisible by 2 and then numbers which divisible by 3, and then by 5, by 7, by 11 and so on...
I don't know why, but when the program runs on debug mode, it finishes successfully and immediately. but on release mode it takes about 3.5 minutes. why is the big difference?
I don't know if the problem is inefficiency or something else. If the code is too long to understand, it's okay, I will be happy just for guidance.
This is the code:
int main()
{
printf("What is the size of the array?\n");
scanf("%d",&arrySize);
printf("Enter %d integers\n",arrySize);
inputArry(arry,arrySize,0);
arrangeArry(arry,1,arrySize);
printArry(arry,0,arrySize);
main();
return 0;
}
//insert numbers to array
void inputArry (int arry[], int size, int index)
{
if (index>size-1)
return;
scanf("%d",&arry[index]);
inputArry(arry,size,index+1);
}
void arrangeArry (int arry[], int index, int size) // Arrange array
{
if (index >=size)
return;
arrangeSubArry(arry,index);
arrangeArry(arry,index+1,size);
}
// Given arranged array except the last number, this
// function arranges the array including the last number
void arrangeSubArry (int arry[], int index)
{
int temp=0;
if (index==0)
return;
if (dividedBy(arry[index],2)<dividedBy(arry[index-1],2))
{
temp=arry[index];
arry[index]=arry[index-1];
arry[index-1]=temp;
arrangeSubArry(arry,index-1);
}
}
// Gives the first prime number that int num is divided by
int dividedBy (int num, int counter)
{
if (num==1||num==0||isPrime(num,sqrt(num))==1)
return 1;
if (isPrime(counter,sqrt(counter))==1)
{
if (num%counter==0)
return counter;
}
dividedBy(num, counter+1);
}