Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Math Library Functions in C Programming

August 25, 2013 Posted by: GPA Views: 906 0 comments

Math library functions allow you to to do mathematical calculations. For it you must include the math header by using the preprocessor directive #include <math.h> when using functions in the math library. In this table are presented more popular math functions.

Function Description Example
sqrt(x) square root of x sqrt(4.0) is 2.0
exp(x) exponential function e^x exp(1.0) is 2.718282
log(x) natural logarithm of x (base e) log(2.718282) is 1.0
log10(x) logarithm of x (base 10) log10(1.0) is 0.0
fabs(x) absolute value of x fabs(13.5) is 13.5
ceil(x) rounds x to the smallest integer not less than x ceil(9.2) is 10.0
floor(x) rounds x to the largest integer not greater than x floor(8.2) is 8.0
pow(x) x raised to power y (x y ) pow(2,3) is 8.0
fmod(x, y) remainder of x/y as a floating-point number fmod(13.657, 2.333) is 1.9
sin(x) trigonometric sine of x (x in radians) sin(0.0) is 0.0
cos(x) trigonometric cosine of x (x in radians) cos(0.0) is 1.0
tan(x) trigonometric tangent of x (x in radians) tan(0.0) is 0.0

Example

  

#include <stdio.h>
#include
<stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
printf("sqrt(9.0) = %.2f\n",sqrt(9.0));
   printf("exp(1.0) = %.2f\n",exp(1.0));
   printf("log(2.7182) = %.2f\n",log(2.7182));
   printf("log10(1.0) = %.2f\n",log10(1.0));
   printf("fabs(12.5) = %.2f\n",fabs(12.5));
   printf("ceil(9.2) = %.2f\n",ceil(9.2));
   printf("floor(8.2) = %.2f\n",floor(8.2));
   printf("pow(2,3) = %.2f\n",pow(2,3));
   printf("fmod(13.657,2.333) = %.2f\n",fmod13.657,2.333));
   printf("sin(0.0) = %.2f\n",sin(0.0));
   printf("cos(0.0) = %.2f\n",cos(0.0));
   printf("tan(0.0) = %.2f\n",tan(0.0));
   system("PAUSE");
   return 0;
}


Output

Math Library Functions in C example

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe