打开pow的正确姿势
x=pow((long double)n,m);
或
y=round(pow(n,m));
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
int n,m;
long long x,y;
int main(){
freopen("data.txt","r",stdin);
freopen("1.txt","w",stdout);
scanf("%d%d",&n,&m);
x=pow((long double)n,m);
y=round(pow(n,m));
cout<<x<<' '<<y<<'\n';
}
本文介绍了如何正确使用C++中的pow函数进行幂运算,并展示了两种不同的实现方式:一种使用longdouble来确保精度,另一种使用round函数来获取四舍五入后的结果。通过示例代码演示了如何读取输入并输出计算结果。
1244

被折叠的 条评论
为什么被折叠?



