C/Math/Absolute Value

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Get absolute value of long integer parameter: how to use labs

#include <stdio.h>
#include <math.h>
int main ()
{
  int n, m;
  n = labs( 645537 );
  m = labs( -100010 );
  printf (" n = %d\n", n);
  printf (" m = %d\n", m);
  return 0;
}


How to get absolute value for float

#include <math.h>
#include <stdio.h>
int main(void)
{
  printf("%1.1f %1.1f", fabs(1.0), fabs(-1.0));
  return 0;
}


Return absolute value of floating-point: fabs

#include <stdio.h>
#include <math.h>
int main ()
{
  printf ("Absoulte value of 3.14 is %lf\n", fabs (3.14) );
  printf ("Absoulte value of -11.6 is %lf\n", fabs (-11.6) );
  return 0;
}


Return absolute value of integer parameter: how to use abs

#include <stdio.h>
#include <math.h>
int main ()
{
  int n, m;
  n = abs( 3 );
  m = abs( -1 );
  printf (" n = %d \n", n);
  printf (" m = %d\n", m);
  return 0;
}