CCF-CSP 202212-1 Present Value Calculation

topic link

  • Present value is the value today of a future (or past) payment or stream of payments. Or understood as: When the value of costs or benefits is measured in today's cash
  • The idea of ​​this question is to convert future expenditure and income into today's present value to calculate the profit and loss of the project
code show as below
#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;
}

Guess you like

Origin blog.csdn.net/weixin_64632836/article/details/129350586