c++题解:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
double i;
double tmp=0;
scanf("%d%lf",&n,&i);
for(int j=0;j<=n;j++)
{
int x;
scanf("%d",&x);
tmp+=x*pow(1+i,-j);
}
printf("%.3f",tmp);
return 0;
}
注:
double 双精度浮点数
float 单精度浮点数
scanf函数中:
%f: 表示单精度浮点型,默认输出小数点后六位
%lf:表示双精度浮点型,默认输出小数点后六位
选择%f还是%lf看类型是float还是double
printf函数中:
只能用%f,默认输出小数点后六位
printf("%.3f",&a); //表示控制输出小数点后三位
printf("%6.3f",&a); //表示输出浮点数整体占位6,包括小数点,小数点后三位