Maths Funtions in 'C'
- if you want to compute 'LOG,COS,etc' varies mathematics function Than you can use #include<math.h> library of 'C'.
- C language provides varies built in functions,for computing mathematics functions like logarithmic, trigonometric functions,etc.
- for computing varies function then you have to specify header file #include<math.h> at the top as the header file.
Function | Description | |||
---|---|---|---|---|
cos(x) | Sine of x,x in radians | |||
cos(x) | Cosine of x,x in radians | |||
exp(x) | Exponential function ex | |||
log(x) | logarithm In(x) | |||
power(x,y) | Power of x to y | |||
ceil(x) | Smallest integer greater than X | |||
floor(x) | Largest integer smaller than x |
Lets see all this function by an example
#include<stdio.h> //header file
#include<math.h>
void main()
{
float sine,cosine,logarathmic,expo; // declaration of variables
int power,ceils,flor;
sine = sin(90);
cosine = cos(90);
logarathmic = log(1.85);
expo = exp(1.23);
power = pow(16,2);
ceils = ceil(10.23);
flor = floor(10.23);
printf(" sine of 90 is %f\n",sine); //sine function of 90
printf(" cosine of 90 is %f\n",cosine); // cos function for 90
printf(" log of 1.85 is %f\n",logarathmic); // log value of 1.85
printf(" e raise to 1.23 is %f\n",expo); // exponential function for 1.23
printf(" Square of 16 is %d\n",power);
printf(" ceil value of 10.23 is %d\n",ceils); //upper value for 10.23 is 11
printf(" floor values of 10.23 is %d\n",flor); //lower value for 10.23 is 10
}
#include<stdio.h> //header file #include<math.h> void main() { float sine,cosine,logarathmic,expo; // declaration of variables int power,ceils,flor; sine = sin(90); cosine = cos(90); logarathmic = log(1.85); expo = exp(1.23); power = pow(16,2); ceils = ceil(10.23); flor = floor(10.23); printf(" sine of 90 is %f\n",sine); //sine function of 90 printf(" cosine of 90 is %f\n",cosine); // cos function for 90 printf(" log of 1.85 is %f\n",logarathmic); // log value of 1.85 printf(" e raise to 1.23 is %f\n",expo); // exponential function for 1.23 printf(" Square of 16 is %d\n",power); printf(" ceil value of 10.23 is %d\n",ceils); //upper value for 10.23 is 11 printf(" floor values of 10.23 is %d\n",flor); //lower value for 10.23 is 10 }
Output:
sine of 90 is 0.893997
cosine of 90 is -0.448074
log of 1.85 is 0.615186
e raise to 1.23 is 3.421230
Square of 16 is 256
ceil value of 10.23 is 11
floor values of 10.23 is 10
cosine of 90 is -0.448074
log of 1.85 is 0.615186
e raise to 1.23 is 3.421230
Square of 16 is 256
ceil value of 10.23 is 11
floor values of 10.23 is 10
0 Comments
Post a Comment