Math Functions in C Programming

Math Functions in C Programming

C math functions with examples; Through this tutorial, you will learn everything about math or mathematical functions in a c programming language with the help of examples.

Math Functions in C Programming

  • What are math functions in C
  • List of Math Functions in C
  • Examples of Math Functions in C
    • Floor function in c
    • C program to find square root of a number with sqrt
    • C program to round float number
    • C program to find power of a number using pow function
    • C program for exponential function

What are math functions in C

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

For example; If you want to find the square root of a number in the C program. For this, you have to use sqrt() meth function in c program.

List of Math Functions in C

There is the list of math functions in c; as follows:

FunctionDescription
floor ( )This function returns the nearest integer which is less than or equal to the argument passed to this function.
round ( )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 from “.6 to .9”, it returns the integer value greater than the argument.
ceil ( )This function returns nearest integer value which is greater than or equal 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 xth 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.
sqrt ( )This function is used to find square root of the argument passed to this function.
pow ( )This is used to find the power of the given number.
trunc.(.)This function truncates the decimal value from floating point value and returns integer value.

Examples of Math Functions in C

  • Floor function in c
  • C program to find square root of a number with sqrt
  • C program to round float number
  • C program to find power of a number using pow function
  • C program for exponential function

Floor function in c

Using the math floor() function, you can find largest integer that is smaller than or equal to x (ie: rounds downs the nearest integer); as follows:

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

C program to find square root of a number with sqrt

Using the math sqrt() function, you can find square root of a number with sqrt in c program ; as follows:

#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;
}

C program to round float number

Using the math round() function, you can round the nearest value of a given input in c program; as follows:

#include <stdio.h>
#include <math.h>
int main ()
{
    for(double r=10;r<=20;r+=1.1)
    printf("round of  %.1lf is  %.1lf\n", r/5.0, round(r/5.0));
    return 0;
    
}

C program to find power of a number using pow function

Using the math pow() function, you can find power of a number using pow function in c program; as follows:

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

C program for exponential function

Using the math exp() function, you can computes e (2.71828) raised to the power of the given argument in c program; as follows:

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

int main() {
  double x = 12.0, result;
  result = exp(x);
  printf("Exponential of %.2lf = %.2lf", x, result);
  return 0;
}

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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