C语言教程:数学函数实例

2018-10-1307:51:14编程语言入门到精通Comments3,335 views字数 716阅读模式

C语言中允许我们通过使用<math.h>头文件中定义的函数来执行数学运算。 <math.h>头文件包含用于执行sqrt()pow()ceil()floor()等数学运算的各种方法。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6621.html

C语言数学函数

math.h头文件中定义和实现有各种方法。math.h头文件的常用函数如下。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6621.html

序号函数描述
1ceil(number)舍入给定数字。它返回大于或等于给定数字的整数值。
2floor(number)舍入给定数字。它返回小于或等于给定数字的整数值。
3sqrt(number)返回给定数字的平方根。
4pow(base, exponent)返回给定数字的幂值。
5abs(number)返回给定数字的绝对值。

数学函数实例

我们来看一个使用math.h头文件中的数学函数的简单例子。创建一个源代码文件:math-function.c,其代码实现如下 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6621.html

#include<stdio.h>  
#include<math.h>  
void 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 \n", abs(-12));

}
C

执行上面示例代码,得到以下结果 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6621.html

4.000000
4.000000
3.000000
3.000000
4.000000
2.645751
16.000000
27.000000
12
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6621.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/6621.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定