Arithmetic function

ARITHMETIC FUNCTIONS

0  0 2016-09-07 03:17:00

Arithmetic functions are used to perform mathematical operations in a program in C Language.
There are many functions that are used to perform mathematical operations like abs(),round(),value() etc.
List of inbuilt arithmetic functions in C language:
•Arithmetic Functions are supported by “math.h” and “stdlib.h” header files .

S.no Functions Description
1. abs ( ) This function is used to return the absolute value of an integer. The absolute value of a number is always positive. C supports only integer value. <stdlib.h> support this function.
2. value ( ) This function is used to get nearest integer value which is less than or equal to the argument passed in the function.
3. round() This function is used to get the nearest integer value of the float/double/long double argument passed in function. If passed decimal value is from “.1 to .5”, it returns integer value less than the argument. If passed decimal value is from “.6 to .9”, it returns the integer value greater than the argument. <math.h> is support this function.
4. ceil ( ) This function is used to get nearest integer value which is greater than or equal to the argument passed in function.
5. sin ( ) Used for calculate sine value in c language.
6. cos ( ) Used for calculate cosine value.
7. cosh ( ) Used for calculate hyperbolic cosine value.
8. exp ( ) This function is using for calculate the exponential ‘e’ to the xth power.
9. tan ( ) This function is using for calculate tangent value.
10. tanh ( ) This function is using for calculate hyperbolic tangent value.
11. sinh ( ) Used for calculate hyperbolic sine value.
12. log ( ) Using for calculates natural logarithm value.
13. log10 ( ) Using for calculate base 10 logarithm value.
14. sqrt ( ) Using for finding square root of the argument passed in argument.
15. pow ( ) This function  is used to find the power of a number passed in argument.
16. trunc( ) This function is used to truncate the decimal value from floating point value and returns integer value.

Examples :
1. #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
          int a = abs(500);
          int b = abs(-100);   
          printf("value of a is  = %d\n", a);
          printf("value of b is = %d \n",b);
          return 0;
    }

Output: value of a is= 500
               value of b is= 100

2. #include <stdio.h>
    #include <math.h>
    int main()
    {
       float a=4.1, b=5.8, c=-5.3, d=-8.9;
       printf("value of  %f is =  %f\n", a, value(a));
       printf("value of  %f is = %f\n", b, value(b));
       printf("value of  %f is = %f\n", c, value(c));
       printf("value of  %f is = %f\n", d, value(d));
       return 0;
    }
 
Output:
value of 5.100000 is = 4.000000
value of 5.900000 is = 6.000000
value of -5.400000 is = -5.000000
value of -6.900000 is = -9.000000

3. #include <stdio.h>
    #include <math.h>
    int main()
    {
       float a=7.4, b=7.6;
       printf("value of  %f is  %f\n", a, round(a));
       printf("value of  %f is  %f\n", b, round(b));
       return 0;
}

Output:
value of 5.400000 is 7.000000
value of 5.600000 is 8.000000

Comments (0)

Post Your Comments

Headquarter



Hong Kong Office



Find Us On

Ziuby
Ziuby