简单题(62%)
简单题
https://ac.nowcoder.com/acm/problem/15185
链接https://ac.nowcoder.com/acm/problem/15185
#include <iostream>
#include <cmath>
using namespace std;
const double e =2.718281828459;
int main() {
int n;
cin >> n;
while (n--) {
int a, b, c;
cin >> a >> b >> c;
double w = 1, m = 0;
for (int i = 0; i < a; i++) {
w *= e;
}
for (int i = 0; i < b; i++) {
m += w;
}
printf("%.*f\n",c, m);
}
return 0;
}
纯暴力解法,需要注意e的值越精确结果才能准确、printf()中的“*”表示用动态指定保留的小数位数,只需要在后面输入你想保留的位数。
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,t;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>a>>b>>c;
cout<<fixed<<setprecision(c)<<exp(a)*b<<endl;//exp(x)函数能返回e^x
}
return 0;
}
大佬解法:fixed 来固定小数点后的位数,setprecision(c)并设置精度,计算幂指数函数(e 的 x 次幂),可以使用 <cmath> 头文件中的 exp() 函数。这个函数接受一个参数并返回 e 的这个参数次幂的值。