abs() : absolute value

We will get absolute value by using abs() function.
abs(x)
x = input number .

Example with integer as inputs

#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;
}
12.35
35.45
Your Rating




Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer