I got my test back today and my grade was a 71. I lost 20 points on my test because I didn't correctly write a function to find the smallest number. My final is on Thursday and I need to figure this out before then.

The exam question is:

*"Write the arguments and code for a function called find_smallest() that takes an array of integers and a single integer as arguments. The function will search the array from the first element to the number of elements specified by the second argument and find the value of the smallest element in the array. This value is then returned to the calling function. In the main() program below, the call to find_smallest() would yield a value of z of -38.*"

What I wrote is below.

Code:

#define NUM_ELEMENTS 7
int find_smallest (int x[], int y)
{
int i, smallest, small;
x[0] = x[smallest]
for(i=0;i<y;i++){
if(x[i] <= x[smallest])
x[i]=small;
return(small);
}
}

here is the main that was given

Code:

void main (void)
{
int x[NUM_ELEMENTS] = {89,234,-3,0,45,-38,75};
int y = NUM_ELEMENTS;
int z;
z= find_smallest(x,y);
printf("Smallest value in the array is %d",z);
}