At midnight 4 am,
I was solving the question CM01 got frustrated finding the mistake in this simplest solution in C language and C++ language which went on going WA’s, later on thought to move to C++ and got AC with abs of algorithm in stl
AC solution using abs from STL C++ using abs from algorithm
Finally on single stepping realize that the abs was giving weird answers in C & C++ of stdlib.h header file so did not understood the weird behavior? Does anyone know why abs does not give correct answers in C/C++ of stdib.h while it works properly in C++ from stl.
Final AC solution in C without using abs --> C Solution
P.S. Do check the input/output to understand why abs gives different answers in C than C++.
Thanks in advance!