Latest web development tutorials

C library functions - abs ()

C standard library - <stdlib.h> C standard library - <stdlib.h>

description

C library functionsint abs (int x) Returns the absolute value of x.

statement

Here is () statement abs function.

int abs(int x)

parameter

  • x - the complete value.

return value

This function returns the absolute value of x.

Examples

The following example demonstrates the abs () function is used.

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   int a, b;

   a = abs(5);
   printf("a 的值 = %d\n", a);

   b = abs(-10);
   printf("b 的值 = %d\n", b);
   
   return(0);
}

Let's compile and run the above program, which will result in the following:

a 的值 = 5
b 的值 = 10

C standard library - <stdlib.h> C standard library - <stdlib.h>