Answer the question
In order to leave comments, you need to log in
How to terminate a recursive algorithm?
It is necessary to check whether all elements of the array pass the condition cos(x[i]) > 0, while using a recursive function, each time dividing the array into two parts - 1/3 and 2/3, checking first the first, then, if necessary, second. Stop recursion when 1 - 2 elements are left. Here is what I was able to write, while the code is conditional, so far the function does not return anything, it's all very roughly:
prov (double *a, int N, int border, int border2, flag, exit)
{
if (!exit)
{
if (N == border) {
if (cos(a[N]) > 0)
{
flag = true;
}
else{
exit = true;
}
}
if (!flag)
{
prov (a, (N - border)/3, border, N, flag, exit);
}
else
{
border++;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question