如题:
    简单编写一个应用程序能通过公式: 
e^x =1+x/1!+x^2/2!+x^3/3!+...来计算e^x的值。(注:1!表示的是1的阶乘)

解决方案 »

  1.   


    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    namespace 阶乘 

        class program 
        { 
            static void Main(string[] args) 
            { 
                int i = 1; 
                Console.WriteLine("请输入数字:"); 
                int j = int.Parse(Console.ReadLine()); 
                int x = j;//用来输出 
                for (; j >= 1; j--) 
                { 
                    i = i * j; 
                } 
                Console.WriteLine(x + "的阶乘是  "+ i); 
                Console.ReadLine(); 
            } 
        } 
    }
      

  2.   

    有个帖子已经回了,用winform一样,输出改一下就能用了
    public long Factorial(long x)
    {
        int i = 0;
        long Result = 1;
        for (i = 1; i <= x; i++) {
            Result = Result * i;
        }
        return Result;
    }public decimal ex(decimal x)
    {
        int i = 0;
        decimal result = default(decimal);
        result = 1;
        for (i = 1; i <= 20; i++) {
            result = result + Math.Pow(x, i) / Factorial(i);
        }
        return result;
    }
    protected void form1_Load(object sender, System.EventArgs e)
    {
        Response.Write(ex(1));
    }
      

  3.   


            public long Factorial(long x)
            {
                if (x == 1)
                    return x;
                else
                    return Factorial(x - 1) * x;
            }
            private void txtInput_KeyPress(object sender , KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)Keys.Enter)
                {
                    int x = int.Parse(txtInput.Text);
                    double result = 1;
                    for (int i = 1 ; i <= x ; i++)
                    {
                        result += (double)Math.Pow(x,i) / (double)Factorial(i);
                    }
                    txtOutput.Text = result.ToString();
                }
            }
    long类型只能算到20