求c语言大神指导!Problems:1) The factorial of a nonnegative integer n is written (pronounced “n factorial”) and is defined as follows:=n*(n-1)*(n-2)*.*1(for value of n greater than or equal to 1)and= 1For example,= 5 × 4 × 3 × 2 × 1 = 1

来源:学生作业帮助网 编辑:作业帮 时间:2024/07/18 05:17:24
求c语言大神指导!Problems:1) The factorial of a nonnegative integer n is written (pronounced “n factorial”) and is defined as follows:=n*(n-1)*(n-2)*.*1(for value of n greater than or equal to 1)and= 1For example,= 5 × 4 × 3 × 2 × 1 = 1
xT]OG+ ml>`cRߐi=ΆEE&g҄R+O"O Fj>efgι{gƛᝲrxۛ׳ t0T}^Ǩ93#VER\8װ("&2瘢T`Y+Mk޴6ъ*tMcEN!U㈒ΥT薦[X䦨f`C>^(-|Z!U"Rh8[DWbÈTa%#`/ XFI$H4gdXFGdMЦQ #MNu )2&(G0 H+ӰtME5Լ: Ƒ`䂽/Q 5CkyeFD}%`[Ex> )(- M]SkDͩ:)ׁ`/)5 s0yP:NUr F(SQ5T=(@,O4d6)ՙNIi{lT|]ӧ#r7ףQ?𬷶''Y\xt~Р{T qQl}Z ɋR(Muȓ'C T2MϹ04xª3#7a VwKe{:d?9LJ}oo:ۯ(ߵpoly-n_Bwn\T27C,/ ŒmAky;8 ~MF5UE  jd5/l%d~σ,ZuZ݀01(s/R/IhʛMNgÉ

求c语言大神指导!Problems:1) The factorial of a nonnegative integer n is written (pronounced “n factorial”) and is defined as follows:=n*(n-1)*(n-2)*.*1(for value of n greater than or equal to 1)and= 1For example,= 5 × 4 × 3 × 2 × 1 = 1
求c语言大神指导!
Problems:
1) The factorial of a nonnegative integer n is written (pronounced “n factorial”) and is defined as follows:
=n*(n-1)*(n-2)*.*1(for value of n greater than or equal to 1)
and
= 1
For example,= 5 × 4 × 3 × 2 × 1 = 120
Factorials may be used to estimate the value of the mathematical constant e by using the following formula:
e=1+ 1/1!+ 1/2!+ 1/3!+.
Write a program that reads a nonnegative integer n and then computes its factorial and an estimate for the mathematical constant e (n in the formula for e will be the same value for which a factorial is found using the first equation).The original number entered by the user,the factorial and the estimate for e should all be printed to the screen.
Finally compute and output the value of using the following formula.x will be input by the user.
e^x = 1+ x/1!+ x^2/2!+x^3/3!+.

求c语言大神指导!Problems:1) The factorial of a nonnegative integer n is written (pronounced “n factorial”) and is defined as follows:=n*(n-1)*(n-2)*.*1(for value of n greater than or equal to 1)and= 1For example,= 5 × 4 × 3 × 2 × 1 = 1

这些英文理解起来真费劲呢,不过我知道了:

#include<stdio.h>
long factorial(int n)/*计算阶乘*/
{
if(n<0) return -1;/*小于0,返回-1说明无效*/
if(n=0) return 1;
return n*factorial(n-1);
}
double xx(double x,int i)/*计算x的整数次方*/
{
if(i==0) return 1;
return xx(x,i-1)*x;
}
double power(int x)/*计算上述级数*/
{
double result=0;/*存放结果*/
double t=0;/*存放每节的结果,目的是为了获取高精度*/
for(int i=0;t<1e-6;i++)
{
t=xx(x,i)/factorial(i);
result+=t;
}
return result;
}
main()
{
int x;
printf("Input an integer number:");/*提示语什么的,你自己看着办好了*/
scanf("%d",&x);
if(x<0){
printf("The factorial of %d is not valid.",x);/*负数的阶乘无效*/
printf("The e is %lf.",power(1));
printf("The Power x of e is %lf.",1/power(-x));/*负a次方等于正a次方的倒数*/
}else{
printf("The factorial of %d is &ld.",x,factorial(x));
printf("The e is %lf.",power(1));
printf("The Power x of e is %lf.",power(x));
}
}