C++编程计算S.当x=0.3,n=10时输出S的值,s=1+x+x^2/2!+x^3/3!+...+x^n/n! ,保留4位小数,求S值。

如题所述

#include<stdio.h>
#include<math.h>
main()
{
float x=0.3,s=0;
int i,j,m;
s=1+x;
for(i=2;i<=10;i++)
{ for(j=1,m=1;j<=i;j++)
m*=j;
s+=pow(x,i)/m;
}

printf("%4.4lf\n",s);
getch();

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-11-19
#include <conio.h>
#include <stdio.h>
#include <math.h>
double factorial(int n){//求阶乘
double sum=1;
for(int i=1;i<=n;i++){
sum=sum*i;
}
return sum;
}
void main()
{
double x=0.3;
int n=10;
double sum=1;
for(int i=1;i<=n;i++)
sum+=pow(x,i)/(factorial(i));
printf("%.4f\n",sum);//保留四位小数
}
第2个回答  2011-11-19
#include<iostream>
#include<math.h>
using namespace std;
int fun1(int n){
int sum=1;
for(int i=1;i<n+1;n++)
sum*=i;
return sum;
}
float fun(int n){
float x=0.3;
if(n==1) return x;
else
return fun(n-1)+(float)pow(x,n)/fun1(n);
}
void main(){
int n=10;
cout<<fun(n)+1<<endl;
}
}
第3个回答  2011-11-19
s=1,x=0.3,n=10,temp=1;
for(int i=1; i<=10; i++)
{
temp *= i;
s += x^i/temp;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网