0

Absolute value

Hey guys may someone help me to solve this excercise: Find if there are two equal absolute values in a given vector ? 🙏🏻 🙏🏻

3rd Feb 2020, 7:33 PM
SINAN SINAJ
SINAN SINAJ - avatar
1 ответ
+ 2
One possible strategy would be to loop over the array, then compare the absolute value of the current element to the absolute values of all the elements behind the current element using an inner loop. If any match is found, you return true and stop the loops, otherwise if the loops finish by themselves you know there are no matches and return false. Computing the absolute value can be done via the predefined abs() or fabs() function: https://en.cppreference.com/w/c/numeric/math/abs https://en.cppreference.com/w/c/numeric/math/fabs
3rd Feb 2020, 7:48 PM
Shadow
Shadow - avatar