0
whats wrong in this code?
int solve(int *A, int Length) { int ans = 0; for (int i = 1; i < A Length; i++) { if (A[i] < ans) { ans = A[i]; } } return ans;
2 Answers
+ 2
Doesn't look like the entire code, but you start indexing at 1 when I guess you want to start at 0.
However, if you are searching for the smallest element of the array, it would make sense to keep the starting index and initialize "ans" to A[ 0 ] instead, because right now the function would only return something other than 0 if there are negative integers in the array.
Also, the 'A' in front of "Length" in the loop condition does not belong there, and the function lacks a closing brace, possibly due to the cut copy.
0
It compiles fine, but not able to find the bug.