Return some value via return
statement regardress of value of lookup[i][j]
.
For example, return 0
because I don’t know the correct value to return.
int f(long long int arr[], long long int x, long long int y)
{
long long int i = x, j = y;
if(lookup[i][j] == 0)
{
if(i == j)
lookup[i][j] = arr[i];
else
lookup[i][j] = min(f(arr, i, j-1), arr[j]);
return 0; /* add this line */
}
else
return (lookup[i][j]);
}
Alternatively, I guess the function should be like this:
int f(long long int arr[], long long int x, long long int y)
{
long long int i = x, j = y;
if(lookup[i][j] == 0)
{
if(i == j)
lookup[i][j] = arr[i];
else
lookup[i][j] = min(f(arr, i, j-1), arr[j]);
}
/* remove else here */
return (lookup[i][j]);
}
2
solved How to remove “end of non-void function” error in c++? [duplicate]