LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   printing negative value as positive (https://www.linuxquestions.org/questions/programming-9/printing-negative-value-as-positive-319476/)

hubabuba 05-02-2005 05:21 PM

printing negative value as positive
 
Hi

I can't get this right.
A result of a subtraction of one int variable with positive value from another int variabe with positive value, produces a negative value and stores it in the third int value. How can i print the negative value as positve (without the minus sign)?

Thanks

ahwkong 05-02-2005 05:46 PM

what language?

If the language provide abs() (absolute value), you can apply this to the neg num before printing.

hubabuba 05-02-2005 06:54 PM

C Language.

I'm a begginer, I don't know if it provides abs() .

ahwkong 05-02-2005 08:45 PM

Being beginner is no excuse for not looking it up yourself.

Using google and keyword "abs c" I found some reference right away.

itsme86 05-03-2005 11:45 AM

Just check if the number is negative. If it is then multiply it by -1.

hubabuba 05-03-2005 01:41 PM

Thanks for your replies. Worked out how to use the abs().


All times are GMT -5. The time now is 01:51 AM.