WV.40-求自然對數e的近似值
阿新 • • 發佈:2019-02-20
問題及程式碼:
執行結果:
知識點總結:
e=1+1/1!+1/2!+1/3!+...+1/n!
/* *Copyright (c)2014,煙臺大學計算機與控制工程學院 *All rights reserved. *檔名稱:e.cpp *作 者:單昕昕 *完成日期: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函式的呼叫。