how do you eliminate the - sign of an negative integer regardless if the integer is positive or negative
Printable View
how do you eliminate the - sign of an negative integer regardless if the integer is positive or negative
The abs function declared in <stdlib.h> or <math.h>.
Code:if (i < 0) {
i = -i;
}
...or even...
i = abs(i);
or you can use if
orCode:if (x < 0)
x = -x;
Code:x = (x > 0)? x : (-x);
you can use the fbas funciotn as well
fabs(-8.75) -- > 8.75
synatx : - fabs( value) --> declared in <math.h>
s.s.harish
x-=(x+-1);
Quote:
Originally Posted by Quantum1024
Well, it works perfectly for x = 1 and x = -1. Did you test it for other values of x?
(I hope this isn't the beginning of a continuing thread that shows more and more baroque expressions that set things equal to 1. I really hate that stuff.)
Regards,
Dave
"If it ain't baroque, don't fix it."