C/Math/Absolute Value


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из 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;
}