Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Session-7 Part-1 - Mathematical Function From Math Header File in C

This document provides descriptions and examples of various math functions available in the C math.h library. It lists functions like floor, ceil, round, trigonometric functions, exponential, logarithmic, square root and power functions. It also includes example programs demonstrating the use of these functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Session-7 Part-1 - Mathematical Function From Math Header File in C

This document provides descriptions and examples of various math functions available in the C math.h library. It lists functions like floor, ceil, round, trigonometric functions, exponential, logarithmic, square root and power functions. It also includes example programs demonstrating the use of these functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

The source of entire document is :

https://www.fresh2refresh.com/c-programming/c-function/c-math-h-library-functions/

Function Description

This function returns the nearest integer which is less than or equal to the
floor ( ) argument passed to this function.

This function returns the nearest integer value of the float/double/long


double argument passed to this function. If decimal value is from “.1 to
.5”, it returns integer value less than the argument. If decimal value is
round ( ) from “.6 to .9”, it returns the integer value greater than the argument.

This function returns nearest integer value which is greater than or equal
ceil ( ) to the argument passed to this function.

sin ( ) This function is used to calculate sine value.

cos ( ) This function is used to calculate cosine.

cosh ( ) This function is used to calculate hyperbolic cosine.

exp ( ) This function is used to calculate the exponential “e” to the x th power.

tan ( ) This function is used to calculate tangent.

tanh ( ) This function is used to calculate hyperbolic tangent.

sinh ( ) This function is used to calculate hyperbolic sine.

log ( ) This function is used to calculates natural logarithm.

log10 ( ) This function is used to calculates base 10 logarithm.

This function is used to find square root of the argument passed to this
sqrt ( ) function.

pow ( ) This is used to find the power of the given number.

This function truncates the decimal value from floating point value and
trunc.(.) returns integer value.

EXAMPLE PROGRAM FOR ABS( ) FUNCTION IN C:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int m = abs(200); // m is assigned to 200
int n = abs(-400); // n is assigned to -400

printf("Absolute value of m = %d\n", m);


printf("Absolute value of n = %d \n",n);
return 0;
}
EXAMPLE PROGRAM FOR FLOOR( ) FUNCTION IN C:

#include <stdio.h>
#include <math.h>
int main()
{
float i=5.1, j=5.9, k=-5.4, l=-6.9;
printf("floor of %f is %f\n", i, floor(i));
printf("floor of %f is %f\n", j, floor(j));
printf("floor of %f is %f\n", k, floor(k));
printf("floor of %f is %f\n", l, floor(l));
return 0;
}

EXAMPLE PROGRAM FOR ROUND() FUNCTION IN C:

#include <stdio.h>
#include <math.h>
int main()
{
float i=5.4, j=5.6;
printf("round of %f is %f\n", i, round(i));
printf("round of %f is %f\n", j, round(j));
return 0;
}

EXAMPLE PROGRAM FOR CEIL() FUNCTION IN C:

#include <stdio.h>
#include <math.h>
int main()
{
float i=5.4, j=5.6;
printf("ceil of %f is %f\n", i, ceil(i));
printf("ceil of %f is %f\n", j, ceil(j));
return 0;
}

EXAMPLE PROGRAM FOR SIN(), COS(), TAN(), EXP() AND LOG() IN C:

#include <math.h>

int main()

{
float i = 0.314;
float j = 0.25;
float k = 6.25;
float sin_value = sin(i);
float cos_value = cos(i);
float tan_value = tan(i);
float sinh_value = sinh(j);
float cosh_value = cosh(j);
float tanh_value = tanh(j);
float log_value = log(k);
float log10_value = log10(k);
float exp_value = exp(k);

printf("The value of sin(%f) : %f \n", i, sin_value);


printf("The value of cos(%f) : %f \n", i, cos_value);
printf("The value of tan(%f) : %f \n", i, tan_value);
printf("The value of sinh(%f) : %f \n", j, sinh_value);
printf("The value of cosh(%f) : %f \n", j, cosh_value);
printf("The value of tanh(%f) : %f \n", j, tanh_value);
printf("The value of log(%f) : %f \n", k, log_value);
printf("The value of log10(%f) : %f \n",k,log10_value);
printf("The value of exp(%f) : %f \n",k, exp_value);
return 0;

EXAMPLE PROGRAM FOR SQRT() FUNCTION IN C:

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

int main()
{
printf ("sqrt of 16 = %f\n", sqrt (16) );
printf ("sqrt of 2 = %f\n", sqrt (2) );
return 0;
}

EXAMPLE PROGRAM FOR POW() FUNCTION IN C:

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

int main()
{
printf ("2 power 4 = %f\n", pow (2.0, 4.0) );
printf ("5 power 3 = %f\n", pow (5, 3) );
return 0;
}

EXAMPLE PROGRAM FOR TRUNC( ) FUNCTION IN C:

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

int main()
{
printf ("truncated value of 16.99 = %f\n", trunc (16.99) );
printf ("truncated value of 20.1 = %f\n", trunc (20.1) );
return 0;
}

You might also like