Math functions are use to perform mathematical operations such as sqrt(), pow(), ceil(), floor() etc. in the C programming language.

Floor() math function

This function returns the nearest integer which is less than or equal to the argument passes to this function is knows as Floor() Math Function.

#include <stdio.h>
#include <math.h>
int main()
{
double p= -8.43;
int final;
final = floor(p);
printf("Floor value of %.2f = %d", p, final);
return 0;
}

Output value

Output value

Ceil () math function

Ceil function returns nearest integer value which is greater than or equal to the argument passes to this function is knows as Ceil() Math Function.

Syntax

  • double ceil (double b)

Example

Input value

#include <stdio.h>
#include <math.h>
int main()
{
float p, cr;
printf("  Enter any Numeric element :  ");
scanf("%f", &p);
cr = ceil(p);
printf("\n The  Value of %.2f = %.4f ", p, cr);
return 0;
}

Output Value

Output value

Sqrt () math function

Sqrt function is use to find square root of the argument passes to this function is knows as Sqrt()

Math Function

Syntax

  • sqrt( arg)

Example

Input value

#include <stdio.h>
#include <math.h>
int main()
{
double n,output;
printf("Enter a number\n");
scanf("%lf", &n);
output = sqrt(n);
printf("Square root of %.2lf = %f", n,output);
return 0;}

Output value

Output value

Round () math function

Round function returns the nearest integer value of the float, double or long double argument passes to Round() Math Function. 

Syntax

  • int round(arg)

Example

Input value

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

int main()
{
    printf("\n The Round Value = %.2f ", round(1.75));
    printf("\n The Round Value = %.2f ", round(16.05));
    printf("\n The Round value = %.2f ", round(15.02));
    
    printf("\n The Round Value = %.2f ", round(-15.36));
    printf("\n The Round Value = %.2f ", round(-28.02));
    printf("\n The Round Value = %.2f \n", round(-908.58));
    
    return 0;
}

Output value

Output value

Pow () math function

It is use to find the power of the given number.

Example

input value

#include <stdio.h>
#include <math.h>
int main()
{
int s, e, u;
printf("\n Enter the numbers :  \n");
scanf("%d %d", &e, &u);
s = pow(e, u);
printf("\n The result of %d Power %d = %d ", e, u ,s);
return 0;
}

Output value

Output value

Trun() math function

Truncates the decimal value from floating point value and returns integer value is knows as Trun() Math Function.

Syntax

  • double trunc(a);

Example

Input value

#include <stdio.h>
#include <math.h>
void main() {
double x, y, v, u ;
v = 85.23;
u = 78.96;
x = trunc(v);
y = trunc(u);
printf("The value of v: %lf\n",x);
printf("The value of v: %lf\n",y);
}

Output value

Output value

Fmod() maths function

Syntax

  • double fmod(double I, double j)

Example

Input value

#include<stdio.h>
#include<math.h>
int main(){
double p;
double a;
double n;
printf("Enter the first number : ");
scanf("%lf",&p);
printf("Enter the second number : ");
scanf("%lf",&a);
printf("fmod(firstNumber,secondNumber) is %lf \n",fmod(p,a));
}

Output value

Output value

Trigonometric Functions

Sin() math function

It is use to calculate sine value.

Syntax

  • return type sin(y);

Example

Input value

#include <stdio.h>
#include <math.h>
int main()
{
double x;
double y;
x = 6.2;
y = sin(x);
printf("sin(%.2lf) = %.2lf\n", x, y);
x = 60;
y = sin(x);
printf("sin(%.2lf) = %.2lf\n", x, y);
return 0;
}

Output value

Output value

Sinh() maths function

It is use to calculate hyperbolic sine.

Syntax

  • double sinh(x);

Example

Input value

#include <stdio.h>
#include <math.h>
#define PI 3.141592654
int main()
{
double u = 4.89, x;
x = sinh(u);
printf("Sine hyperbolic of %.2lf is = %.2lf", u, x);
return 0;
}

Output Value

Output value

Cos() maths function

It is use to calculate cosine.

Syntax

  • return type cos(argument);

Example

Input value

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

#define PI 3.14159265

int main () {
   double a, var, d;

   a = 45.0;
   d = PI / 180.0;
   var = cos( a*d );
   printf("The cosine of %lf is %lf degrees\n", a, d);
   
   a = 120.0;
   d = PI / 180.0;
   var = cos( a*d );
   printf("The cosine of %lf is %lf degrees\n", a, d);
   
   return(0);
}

Output value

Output Value

Cosh() math function

It is use to calculate hyperbolic cosine.

Syntax

  • double cosh(y);

Input value

#include <stdio.h>
#include <math.h>
int main ()
{
double s, x;
s = 0.5;
x = cosh(s);
printf("Hyperbolic cosine of %lf is = %lf\n", s, x);
s = -0.7;
x = cosh(s);
printf("Hyperbolic cosine of %lf is = %lf\n", s, x);
return 0;}

Output value

Output Value

Tan() Math function

It is use to calculate tangent.

Syntax

  • double tan(arguments);

Example

Input value

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

int main()
{
    double a;
    double result;

    a = 5.6;
    result = tan(a);
    printf("tan(%.2lf) = %.2lf\n", a, result);

    a = -9.3;
    result = tan(a);
    printf("tan(%.2lf) = %.2lf\n", a, result);


    return 0;
}

Output value

Output value

Tanh() Math function

It  is use to calculate hyperbolic tangent.

Syntax

  • double tanh( val);

Example

Input value

#include <stdio.h>
#include <math.h>
#define PI 3.141592654

int main()
{
    double x = 0.90, z;
    z = tanh(x);
    printf("Tangent hyperbolic of %.2lf = %.2lf", x, z);
    return 0;
}

Output value

Output Value

Log Arithmetic Functions

Exp() Math function

It function is use to calculate the exponential “e” to the xth power

Syntax

  • return type exp(value);

Example

Input value

#include <stdio.h>
#include <math.h>
int main()
{
double x, y;
printf(" Enter the Value :  ");
scanf("%lf", &x);
y = exp(x);
printf("\n Exponential Value of e power %lf = %lf ", x,y);
printf("\n");
return 0;
}

Output value

Output Value

log() Math function

It is use to calculates natural logarithm.

Syntax

  • double log(arg);

Example

Input value

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

int main () {
   double a, b;
   a = 8.5;

   b = log(a);
   printf("log(%lf) = %lf", a, b);
   
   return(0);
}

Output value

Output value

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about C Programming language please Wikipedia click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *