C语言常用数学函数

C语言常用数学函数(头文件#include "math.h")

abs()函数

函数原型: int abs(int i)
功能: 求整数的绝对值

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%d",abs(-1));
}
![image-20240526235059683](https://gitee.com/cwy0710/image/raw/master/img/image-20240526235059683.png)

labs()函数

函数原型:long labs(long i)
功能:求长型整数的绝对值

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%ld",labs((long)-100000000));
}

image-20240526235145189

fabs()函数

函数原型:double fabs(float i)
功能:求浮点数的绝对值

当然与上面同理

floor()函数

函数原型:double floor(double x)
功能:求不大于x的最大整数

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",floor(2.1));
}

image-20240526235401411

floorf()

函数原型:float floorf(float x)
功能:求不大于x的最大整数

floorl()

函数原型:double floorl(double x)
功能:求不大于x的最大整数

ceil()函数

函数原型:double ceil(double x)
功能:求不小于x的最小整数

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",ceil(2.1));
}

image-20240526235450304

sqrt()函数

函数原型:double sqrt(double x)
功能:求x的平方根。

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",sqrt(4));
}

image-20240526235519683

log()函数

函数原型:double log(double x)
功能:求x的自然对数

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",log(2.717));
}

image-20240526235611597

log10()函数

函数原型:double log10(double x)
功能:求x的常用对数

pow()函数

函数原型:double pow(double x,double y)
功能:求x的y次方

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",pow(10,2));
}

image-20240526235645167

pow10()函数

函数原型:double pow(double x)
功能:求10的x次方

exp()函数

函数原型:double exp(double x)
功能:求e的x次方

sin()函数

函数原型:double sin(double x)

x为弧度值下面同理

#include<stdio.h>
#include "math.h"

#define PI 3.1415926
int main(){
    printf("%f",sin(PI/6));
}

image-20240526235752503

cos()函数

函数原型:double cos(double x)

sin()函数

函数原型:double cos(double x)

asin(),acos(),atan()反函数公式

posted @ 2024-05-27 00:00  Yang0710  阅读(26)  评论(0编辑  收藏  举报