C图书馆数学。h函数

这个 数学H header定义了各种数学函数和一个宏。这个库中所有可用的函数都需要 双重的 作为论据和回报 双重的 结果呢。让我们逐一讨论一些重要的功能。 1. 双层天花板(双层x) :C库函数double ceil(double x)返回大于或等于x的最小整数值。

null
syntax : double ceil(double x)

C

// C code to illustrate
// the use of ceil function.
#include <stdio.h>
#include <math.h>
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = -2.8;
val4 = -2.3;
printf ( "value1 = %.1lf" , ceil (val1));
printf ( "value2 = %.1lf" , ceil (val2));
printf ( "value3 = %.1lf" , ceil (val3));
printf ( "value4 = %.1lf" , ceil (val4));
return (0);
}


输出:

value1 = 2.0value2 = 2.0value3 = -2.0value4 = -2.0

2. 双层(双x): C库函数double floor(double x)返回小于或等于x的最大整数值。

syntax : double floor(double x)

C

// C code to illustrate
// the use of floor function
#include <stdio.h>
#include <math.h>
int main ()
{
float val1, val2, val3, val4;
val1 = 1.6;
val2 = 1.2;
val3 = -2.8;
val4 = -2.3;
printf ( "Value1 = %.1lf" , floor (val1));
printf ( "Value2 = %.1lf" , floor (val2));
printf ( "Value3 = %.1lf" , floor (val3));
printf ( "Value4 = %.1lf" , floor (val4));
return (0);
}


输出:

Value1 = 1.0Value2 = 1.0Value3 = -3.0Value4 = -3.0

3. 双晶圆厂(双x) :C库函数double fabs(double x)返回x的绝对值。

syntax : double fabs(double x)

C

// C code to illustrate
// the use of fabs function
#include <stdio.h>
#include <math.h>
int main ()
{
int a, b;
a = 1234;
b = -344;
printf ( "The absolute value of %d is %lf" , a, fabs (a));
printf ( "The absolute value of %d is %lf" , b, fabs (b));
return (0);
}


输出:

The absolute value of 1234 is 1234.000000The absolute value of -344 is 344.000000

4. 双对数(双x) :C库函数double log(double x)返回x的自然对数(base-e对数)。

syntax : double log(double x)

C

// C code to illustrate
// the use of log function
#include <stdio.h>
#include <math.h>
int main ()
{
double x, ret;
x = 2.7;
/* finding log(2.7) */
ret = log (x);
printf ( "log(%lf) = %lf" , x, ret);
return (0);
}


输出:

log(2.700000) = 0.993252

5. 双对数10(双x) :C库函数double log10(double x)返回x的公共对数(以10为底的对数)。

syntax : double log10(double x)

C

// C code to illustrate
// the use of log10 function
#include <stdio.h>
#include <math.h>
int main ()
{
double x, ret;
x = 10000;
/* finding value of log1010000 */
ret = log10 (x);
printf ( "log10(%lf) = %lf" , x, ret);
return (0);
}


输出:

log10(10000.000000) = 4.000000

6. 双fmod(双x,双y) :C库函数double fmod(double x,double y)返回x除以y的余数。

syntax : double fmod(double x, double y) 

C

// C code to illustrate
// the use of fmod function
#include <stdio.h>
#include <math.h>
int main ()
{
float a, b;
int c;
a = 8.2;
b = 5.7;
c = 3;
printf ( "Remainder of %f / %d is %lf" , a, c, fmod (a, c));
printf ( "Remainder of %f / %f is %lf" , a, b, fmod (a, b));
return (0);
}


输出:

Remainder of 8.200000 / 3 is 2.200000Remainder of 8.200000 / 5.700000 is 2.500000

7. 双sqrt(双x) :C库函数double sqrt(double x)返回x的平方根。

syntax : double sqrt(double x)

C

// C code to illustrate
// the use of sqrt function
#include <stdio.h>
#include <math.h>
int main ()
{
printf ( "Square root of %lf is %lf" , 225.0, sqrt (225.0) );
printf ( "Square root of %lf is %lf" , 300.0, sqrt (300.0) );
return (0);
}


输出:

Square root of 225.000000 is 15.000000Square root of 300.000000 is 17.320508

8. 双功率(双x,双y) :C库函数double pow(double x,double y)将x提升为y的幂,即xy。

syntax : double pow(double x, double y)

C

// C code to illustrate
// the use of pow function
#include <stdio.h>
#include <math.h>
int main ()
{
printf ( "Value 8.0 ^ 3 = %lf" , pow (8.0, 3));
printf ( "Value 3.05 ^ 1.98 = %lf" , pow (3.05, 1.98));
return (0);
}


输出:

Value 8.0 ^ 3 = 512.000000Value 3.05 ^ 1.98 = 9.097324

9 double modf(双x,双*整数) :C库函数double modf(double x,double*integer)返回小数部分(小数后的部分),并将整数设置为整数部分。

syntax : double modf(double x, double *integer)

C

// C code to illustrate
// the use of modf function
#include<stdio.h>
#include<math.h>
int main ()
{
double x, fractpart, intpart;
x = 8.123456;
fractpart = modf (x, &intpart);
printf ( "Integral part = %lf" , intpart);
printf ( "Fraction Part = %lf " , fractpart);
return (0);
}


输出:

Integral part = 8.000000Fraction Part = 0.123456 

10 双经验(双x) :C库函数double exp(double x)返回提升到第x次方的e值。

syntax : double exp(double x)

下面的代码代表

C

// C code to illustrate
// the use of exp function
#include <stdio.h>
#include <math.h>
int main ()
{
double x = 0;
printf ( "The exponential value of %lf is %lf" , x, exp (x));
printf ( "The exponential value of %lf is %lf" , x+1, exp (x+1));
printf ( "The exponential value of %lf is %lf" , x+2, exp (x+2));
return (0);
}


输出:

The exponential value of 0.000000 is 1.000000The exponential value of 1.000000 is 2.718282The exponential value of 2.000000 is 7.389056

11 双cos(双x) :C库函数double cos(double x)返回弧度角x的余弦。

syntax : double cos(double x) 

注: 同样的语法也可用于其他三角函数,如sin、tan等。

C

// C code to illustrate
// the use of cos function
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double x, ret, val;
x = 60.0;
val = PI / 180.0;
ret = cos ( x*val );
printf ( "The cosine of %lf is %lf degrees" , x, ret);
x = 90.0;
val = PI / 180.0;
ret = cos ( x*val );
printf ( "The cosine of %lf is %lf degrees" , x, ret);
return (0);
}


输出:

The cosine of 60.000000 is 0.500000 degreesThe cosine of 90.000000 is 0.000000 degrees

12 双ACO(双x): C库函数double acos(double x)返回x的弧度余弦。

syntax : double acos(double x)

注: 同样的语法也可用于其他圆弧三角函数,如asin、atan等。

C

// C code to illustrate
// the use of acos function
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double x, ret, val;
x = 0.9;
val = 180.0 / PI;
ret = acos (x) * val;
printf ( "The arc cosine of %lf is %lf degrees" , x, ret);
return (0);
}


输出:

The arc cosine of 0.900000 is 25.855040 degrees

13 双谭(双x): C库函数double tanh(double x)返回x的双曲正切。

syntax : double tanh(double x) 

注: 同样的语法也可用于其他双曲三角函数,如sinh、cosh等。

C

// C code to illustrate
// the use of tanh function
#include <stdio.h>
#include <math.h>
int main ()
{
double x, ret;
x = 0.5;
ret = tanh (x);
printf ( "The hyperbolic tangent of %lf is %lf degrees" , x, ret);
return (0);
}


输出:

The hyperbolic tangent of 0.500000 is 0.462117 degrees

本文由 阿维纳什·库马尔·辛格 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享