abs c programming: The function int abs(int x); returns the absolute value of an integer x.
Function prototype of abs
int abs(int x);
- x : This is an integer to convert to an absolute value.
Return value of abs
This function returns absolute value of an integer represented by x.
C program using abs function
The following program shows the use of abs function to find absolute value of an integer.
#include <stdio.h> #include <stdlib.h> int main(){ int value; printf("Enter a number\n"); scanf("%d", &value); printf("Absolute value of %d = %d\n", value, abs(value)); return 0; }
Output
Enter a number 9 Absolute value of 9 = 9
Enter a number -9 Absolute value of -9 = 9
Enter a number 0 Absolute value of 0 = 0