- gf25035 的博客
数学函数
- @ 2025-9-23 15:00:22

#include <iostream>
#include <cmath>
//要有头文件
using namespace std;
int main(){
//求整数5的绝对值
int d=-5;
cout<<abs(d)<<endl;
//求浮点数的绝对值
double e=-3.56;
cout<<fabs(e) <<endl;
//向下取整
double c=3.1678;
cout<<floor(c) <<endl; //向下取整数,输出3
//向上取整
cout<<ceil(c)<<endl;//向上取整数,输出4
//次方
int b=3,bb;
bb=pow(2,b);//求2的3次方
cout<<bb<<endl;
//平方根
double a=4,aa;
aa=sqrt(a);//求根号a的值
cout<<aa<<endl;
//求x的多少次方=y
int a=8;
cout<<log2(a);//输出3,对数函数,求2的多少次方等于a
cout<<log10(100);//输出2
return 0;
}