abs is not a function but is a macro and is used for calculating absolute value of a number.
You can implement you own function as follows:
C programming code for abs
#include <stdio.h> #include <math.h> int main() { int n, result; printf("Enter an integer to calculate it's absolute value\n"); scanf("%d", &n); result = abs(n); printf("Absolute value of %d = %d\n", n, result); return 0; }
long absolute(long value) { if (value < 0) { return -value; } else { return value; } }
No comments:
Post a Comment