• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

How do I find the absolute value of a number in C++?

I have a float variable fNumber.

How do I find the absolute value of fNumber?

In Excel there is a function called ABS() that will let me find the absolute value.  What is the C++ equivalent?
0
shaolinfunk
Asked:
shaolinfunk
  • 2
1 Solution
 
DonConsolioCommented:
    double fabs (      double x );
      float fabs (       float x );
long double fabs ( long double x );

Returns the absolute value of x.

0
 
phoffricCommented:
check out
     double fabs (      double x );
      float fabs (       float x );
long double fabs ( long double x );

http://www.cplusplus.com/reference/clibrary/cmath/fabs/

/* fabs example */
#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("The absolute value of 3.1416 is %lf\n", fabs (3.1416) );
  printf ("The absolute value of -10.6 is %lf\n", fabs (-10.6) );
  return 0;
}

Open in new window

0
 
shaolinfunkAuthor Commented:
thank you!
0
 
shaolinfunkAuthor Commented:
maybe you guys could help me with this one too:

http://www.experts-exchange.com/Programming/Languages/CPP/Q_25685893.html
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now