CCF- CSP 202212-1现值计算

题目链接

  • 现值是将来(或过去)的一笔支付或支付流在当今的价值。或理解为: 成本或收益的价值以今天的现金来计量时
  • 该题思路就是将未来的支出和收入换算为今天的现值,来计算项目的盈亏
代码如下
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
    
    
	int n;
	double i;
	cin >> n >> i;
	double res;
	cin >> res;
	for (int j = 1; j <= n; ++j) {
    
    
		double x;
		cin >> x;
		res += x * pow(1 + i, -j);
	}
	printf("%.3lf\n", res);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_64632836/article/details/129350586
今日推荐