1903:计算多项式的值

 分析:按照题目要求敲就行了。

#include<iostream>
#include<iomanip>
#include<cmath>
using std::cout;
using std::cin;
using std::fixed;
using std::setprecision;
using std::pow;

int main()
{
	int n=0;
	double x = 0;
	cin >>x>> n;
	double result = 0;//记录结果

	for (int i = 0; i <= n; ++i)
	{
		double num = 0;//记录每项数

		for (int j = 0; j <= i; ++j)
		{
			num = pow(x, i);
		}

		result += num;
	}
	cout << fixed<<setprecision(2)<<result;
}

 

おすすめ

転載: blog.csdn.net/LWX3289765163/article/details/121408719