# Thread: Finding Absolute Value in C

1. ## Finding Absolute Value in C

Hello!
Learning C--writing a program that tells if an entered # is positive/negative and gives the absolute value. I have the pos./neg. part all set, but I am needing help with the AV part. C did not understand:
absval=|number|
So I was wonder how can I get C to understand an AV?
:-)

2. IIRC, an absolute value is the positive version of the number. Thus, if you enter 1, the absolute value is 1. If you enter -2, the absolute value is 2.

a=b<0?0-b:b;

Quzah.

3. Thanks!
It works now!

4. umm, one last thing,
what would be the longhand of:
a=b<0?0-b:b;
I mean, using if and elses.
thanks

5. Originally posted by Unregistered
umm, one last thing,
what would be the longhand of:
a=b<0?0-b:b;
I mean, using if and elses.
thanks
That's a bit too easy, you should try it yourself

Look, this how the shorthand works:

>Result = (TestMe)?ReturnThisIfTrue:ReturnThisIfFalse;

Now, I'm sure you know, or can easily find out how the long hand structure is made up. Translation from one to the other is then easy.