ylbtech-Arithmetic:Console-算法[do while]-XX |
![](https://images.cnblogs.com/cnblogs_com/ylbtech/564143/o_ylbtech_arithmetic_dowhile_fun1.jpg)
using System;
namespace ConsoleApplication1
{
class Program
{
/// <summary>
/// ylb: do while
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.Write(fun(2.5));
}
/// <summary>
/// fun
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
static double fun(double x)
{
double f, t;
int n;
f=1.0+x;
t=x;
n=1;
do
{
n++;
t *= x / n; //这儿构思很其巧妙
f += t;
} while (Math.Abs(t) >= Math.Pow(10,-6));
return f;
}
}
}
1.C,Execution Result(运行结果) |
12.1824938304434请按任意键继续. . .