how do you eliminate the - sign of an negative integer regardless if the integer is positive or negative

Printable View

- 03-15-2005kimimarosuper fast question
how do you eliminate the - sign of an negative integer regardless if the integer is positive or negative

- 03-15-2005hk_mp5kpdw
The

*abs*function declared in <stdlib.h> or <math.h>. - 03-15-2005DavTCode:
`if (i < 0) {`

i = -i;

}

...or even...

i = abs(i);

- 03-15-2005modec
or you can use if

Code:`if (x < 0)`

x = -x;

Code:`x = (x > 0)? x : (-x);`

- 03-15-2005ssharish
you can use the fbas funciotn as well

fabs(-8.75) -- > 8.75

synatx : - fabs( value) --> declared in <math.h>

s.s.harish - 03-15-2005Quantum1024
x-=(x+-1);

- 03-15-2005Dave EvansQuote:

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."