Friday, February 11, 2011

Absolute value and Floating-point absolute value function in C Programming Language



Absolute value function in C Programming Language is abs(i), Its return the absolute valu of i. where  i  is any positive or negative  number. It is integer type function. The include file of abs(i) is stslib.h
Observe under program:

#include<stdio.h>

#include<stdlib.h>
int main(void)
{
int a;
scanf("%d",&a);
printf("%d",abs(a));
}
Here I use a integer number. Input it by scanf and print the Absolute value by abs() function.



Floating-point Absolute value function in C Programming Language is fabs(i), Its return the absolute valu of i. where  i  is any positive or negative  Floating-point number. It is double integer type function. The include file of fabs(i) is math.h
Observe under program:


#include<stdio.h>

#include<stdlib.h>
 int main(void)
{
float a;
scanf("%f",&a);
printf("%.2f",fabs(a));
}

Here I use a integer number. Input it by scanf and print the Floating-point Absolute value by abs() function.
If you have any problems tell me by comment. Thanks all.

37 comments em “Absolute value and Floating-point absolute value function in C Programming Language”

Post a Comment

Give your valuable Comment...

 

Programming, Data Structures & Algorithms Copyright © 2011 -- Template created by JAK -- Powered by Blogger