0
3.8kviews
State any 2 library functions in math.h along with its uses.

Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 4M

Year: Dec 2013, Dec 2015

1 Answer
0
73views
  • Math.h header file (<math.h>) of c programming language contains constants and functions to perform mathematical operations.

    • You can use functions of math.h in your c programs to calculating absolute value of a number, calculating logarithms and using trigonometric functions to calculate sine, cosine of an angle.

Math.h functions:

1)  abs         5) sqrt
2)  cos         6) sin
3)  floor           8) ceil
4)  log         9) log10
5)  pow         10) pow10

Sin (): Sin function returns sine of an angle (in radian).

Syntax: double sin (double);

Program code:

#include <stdio.h>
#include <math.h>
int main(){
    double result, x = M_PI/6;
    result = sin(x); 
    printf("Sin(%lf) = %.2lf\n", x, result);
    return 0;
}

Output: Sin (0.523599) = 0.50

Cos (): Cos function returns cosine of an angle(in radian).

1 radian = 57.2958(approximately).

Syntax: double cos (double);

Program code:

#include <stdio.h>
#include <math.h>

int main(){
    double result, x = 1.0471;
    result = cos(x);
    printf("Cos(%.4lf) = %.2lf\n", x, result);
    return 0;
}

Output: Cos (1.0471) = 0.50

Please log in to add an answer.