- abs( ) function in C returns the absolute value of an integer. The absolute value of a number is always positive. Only integer values are supported in C.
- “stdlib.h” header file supports abs( ) function in C language. Syntax for abs( ) function in C is given below.
int abs ( int n );
Example program for abs( ) function in C:
#include <stdio.h> #include <stdlib.h> int main() { int m = abs(200); // m is assigned to 200 int n = abs(-400); // n is assigned to -400 printf("Absolute value of m = %d\n", m); printf("Absolute value of n = %d \n",n); return 0; }
Output:
Absolute value of m = 200 Absolute value of n = 400 |
0 comments:
Post a Comment