#include <stdio.h>
#include <math.h>
int main(void){
int x,y;
x=12;
y=-35;
x = abs(x);
y = abs(y);
printf("%d \n", x);
printf("%d", y);
return 0;
}
The above code will give this output.
12
35
Example with float variables by using fabs()
#include <stdio.h>
#include <math.h>
int main(void){
float x,y;
x=12.35;
y=-35.45;
x = fabs(x);
y = fabs(y);
printf("%f \n", x);
printf("%f", y);
return 0;
}
Output is here
12.350000
35.450001
Example with long variables by using labs()
#include
#include
#include
int main(void){
long int x,y;
x=12.35;
y=-35.45;
x = labs(x);
y = labs(y);
printf("%ld \n", x);
printf("%ld", y);
return 0;
}