/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:e.cpp *作 者:xydsh *完成日期:2015年2月5日 *版 本 号:v1.0 * *问题描述:求自然对数e的近似值,e=1+1/1!+1/2!+1/3!+...+1/n!。*程序输入:无。*程序输出:e的近似值。*/using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Test{ class Program { static int Main() { double i, e, t; i = e = t = 1; while (1 / t >= Math.Pow(10, -6)) { t *= i; e += 1 / t; i++; } Console.WriteLine("e的近似值为:{0}n", e); Console.ReadKey(); return 0; } }}
运行结果:
e=1+1/1!+1/2!+1/3!+...+1/n!
学习心得:
while语句的使用,pow函数的调用。