Sum of 1/1! + 1/2! + … + 1/n!

        /// <summary>
        /// O(n) algorithm for calculation Sum of 1/0! + 1/1! + 1/2! + … + 1/n!
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        private static double SumOfDivFactorial(int n)
        {
            double sum = 1.0d;
            double temp = 1;
            int i = 1;
            while (i < n + 1)
            {
                temp *= i;
                sum += 1.0d / temp;
                i++;
            }
            return sum;
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s