how do you eliminate the - sign of an negative integer regardless if the integer is positive or negative
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>.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Code:if (i < 0) { i = -i; } ...or even... i = abs(i);
DavT
-----------------------------------------------
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);
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."
Last edited by Dave Evans; 03-15-2005 at 10:19 AM.