日期:2014-05-18  浏览次数:20814 次

问个入门级问题,希望大家帮帮忙~
e=1+1/1!+1/2!+1/3!......1/n!
n为输入值,显示e,怎么写啊?帮帮忙~

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace test2
{
class Program
{
public static float multi(int n)
{
float value = 1;;
for (int i = 1; i <= n; i++)
{
value =(float) value * i;
}
return 1F / value;
}
static void Main(string[] args)
{
System.Console.WriteLine( "please input the value of n: ");
int num;
num = Convert.ToInt32(Console.ReadLine());
float sum=0F;
if(num <0)
{
System.Console.WriteLine( "please input wrong num! ");
}
for (int i = 1; i <= num; i++)
{
sum = sum + multi(i);
}
System.Console.WriteLine( "the result is:{0:g} ",sum);
System.Console.ReadLine();
}
}
}