### Need Some Help Finding the Problem!!!!

Can anyone telling me why my program is returning a negative number at the end...attached is the program I have created any help would be appreciated thank you:

/*Write a recursive function recursiveMinimum that takes an integer array and
the array size as arguments and returns the smallest element of the array. The
function should stop processing and return when it receives an array of 1 element.*/

#include <stdio.h>
#include <time.h>
#include <iostream>

using namespace std;

float recursiveMinimum (int ARRAY[], int n);

int main()

{
int ARRAY[10], i, n = 10;

for (i = 0; i < n; i++)
{
printf("Enter number %i: ", i + 1);
cin >> ARRAY[i];
}

printf("\nThe minimum number is: %.0f\n\n", recursiveMinimum (ARRAY, n - 1));
}

float recursiveMinimum (int ARRAY[], int n)

{
int j;
float smallest = float(ARRAY[n]);

printf("%i %.0f %i", n, smallest, ARRAY[n]);//check

for (j = n; j >= 0; --j)
{
if (smallest > float(ARRAY[j - 1]))
{
smallest = float(ARRAY[j - 1]);

printf("\n%.0f", smallest);//check
}
}
return smallest;
}
when I ran it I did not see a negative number, so what numbers are you using ?

 c:\temp>test124 Enter number 1: 124 Enter number 2: 235 Enter number 3: 111 Enter number 4: 2 Enter number 5: 3 Enter number 6: 5 Enter number 7: 8 Enter number 8: 9 Enter number 9: 6 Enter number 10: 0 9 0 0 The minimum number is: 0
 ``123456789`` `````` for (j = n; j >= 0; --j) { if (smallest > float(ARRAY[j - 1])) { smallest = float(ARRAY[j - 1]); printf("\n%.0f", smallest);//check } }``````

When j is 0, ARRAY[0-1] is outside the bounds of ARRAY.
Topic archived. No new replies allowed.