#include<iostream> using namespace std; void main() { double n=1,i=1,j=1,N,x,s=1; double t=1.0,sum=0; cout<<"请输入一个x的值:"<<endl; cin>>x; cout<<"输入一个N的值"<<endl; cin>>N; while(i<=N) { i++; sum=sum+t; t=(j/n)*s; s=-s; j=j*x;//X的i次方 n=n*i;//i的阶乘 } cout<<"前"<<N<<"项和为"<<sum<<endl; }