Session-7 Part-1 - Mathematical Function From Math Header File in C
Session-7 Part-1 - Mathematical Function From Math Header File in C
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 nearest integer value which is greater than or equal
ceil ( ) to the argument passed to this function.
exp ( ) This function is used to calculate the exponential “e” to the x th power.
This function is used to find square root of the argument passed to this
sqrt ( ) function.
This function truncates the decimal value from floating point value and
trunc.(.) returns integer value.
#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
#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;
}
#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;
}
#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;
}
#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);
#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;
}
#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;
}
#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;
}