You are here:

C++/Positive value

Advertisement


Question
Dear expertise,

Here is the sample of my calculation.

m_fnumber1 - m_fnumber2 = m_fresults;

The situation is like this.
i want the value of the calculation is in positive value.  That mean the "m_fnumber1 > mf_number2"

The question is how i want to get the positive value if "m_fnumber2 > m_fnumber1".

Is it in c++, i can use any simple function to make it work as i request?

regards,
opeye

Answer
Hi,
 It means that you need absolute value of the result which can be obtained using abs() function in C/C++.
Please see the following code:
# include <stdio.h>
# include <stdlib.h>
int main ()
{
       int x;
       int y, result;
       scanf("%d", &x);
       scanf("%d", &y);
       result = abs (x-y);
       printf ("%d\n", result);
       return 0;
}

Regards,
RaiD

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Dharmender Rai

Expertise

I can answer general and system level C/C++ questions.

Experience

I have 5 years of experience in C++.

©2016 About.com. All rights reserved.