I have a question for H.W in my college in C, notice that im not allowed to use absolute value function(abs)
i need to find the minimum value between pair of numbers in given array.
assuming that the array is:
int arr[SIZE] = {1,10, 5,100,15,20,25,30,35,40};
and int diff = 0;
using this code without abs function giving me the wrong answer:
for (int i=0; i<SIZE-1; i++) {
for (int j=i+1; j<SIZE; j++) {
if (arr[i] - arr[j] < diff)
diff = (-1) * (arr[i] - arr[j]);
}
}
The value should be 4 and the code is returning 5. what im missing here?