📜  C math()函数

📅  最后修改于: 2020-10-22 05:47:05             🧑  作者: Mango

C math

C编程使我们能够通过定义在函数中执行数学运算头文件。的头文件包含各种用于执行数学运算的方法,例如sqrt(),pow(),ceil(),floor()等。

C数学函数

math.h头文件中有多种方法。下面给出了math.h头文件的常用功能。

No. Function Description
1) ceil(number) rounds up the given number. It returns the integer value which is greater than or equal to given number.
2) floor(number) rounds down the given number. It returns the integer value which is less than or equal to given number.
3) sqrt(number) returns the square root of given number.
4) pow(base, exponent) returns the power of given number.
5) abs(number) returns the absolute value of given number.

C math示例

让我们看一下math.h头文件中找到的数学函数的简单示例。

#include
#include   
int main(){  
printf("\n%f",ceil(3.6));  
printf("\n%f",ceil(3.3));  
printf("\n%f",floor(3.6));  
printf("\n%f",floor(3.2));  
printf("\n%f",sqrt(16));  
printf("\n%f",sqrt(7));  
printf("\n%f",pow(2,4));  
printf("\n%f",pow(3,3));  
printf("\n%d",abs(-12));   
 return 0;  
}  

输出:

4.000000
4.000000
3.000000
3.000000
4.000000
2.645751
16.000000
27.000000
12