abs()


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. 


Sample Program:


/*
Write a program to calculate an absolute value using math function of C.

*/ 

#include<stdio.h> 
#include<math.h> 

main() { 

 int number, result; 
 printf("Enter a number");
 scanf("%d",&number);
 result = abs(number); 
 printf("Absolute value of %d = %d", number, result); 
 getch(); 
 return 0; 
}

Output: 

Enter a number -99
Absolute value of -99 = 99

Post a Comment

0 Comments