/*
* Copyright(c)2011,烟台大学计算机学院
* All right reserved.
* 文件名称:test.cpp
* 作者: 张凯
* 完成日期:2013年11月03日
* 版本号: v1.0
* 问题描述:关于阶乘的求法
*/
#include <iostream>
using namespace std;
int main()
{
double f=0,p=1;
int i=1,t=1;
while(i<=9)
{
p=p*i;
f=f+t*(1/p);
t=-t;
i++;
}
cout<<"f="<<f<<endl;
return 0;
}
运行结果(如下图)
心得体会:主要是p=p*i 的运用!!!