2026-11-21 18:44:18
发布于:上海
1. pow函数(计算幂)
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << pow(2,3); //底数在前,指数在后
return 0;
}
- 注意:pow函数用的是double定义
2. 算术平方根(开方)
- 名称:sqrt()
- 功能:计算n的算术平方根
- 原型:double sqrt(double n)
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << sqrt(9);
cout << fixed << setpresision(2) << sqrt(9) << endl; // 用“cout”保留两位小数
printf(%2f\n,sqrt(9)); //用“printf”保留两位小数
return 0;
}
3.绝对值(计算绝对值)
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << abs(9); // 整数的绝对值
cout << fabs(-9.9) //浮点数的绝对值
return 0;
}
4.取整(向上取整、向下取整、四舍五入)
向上取整:
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << ceil (5.5);
return 0;
}
向下取整:
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << floor(2.31);
return 0;
}
四舍五入:
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << round(1.5);
return 0;
}
综合一下
这里空空如也












有帮助,赞一个