/******************************************************/ /* Introduction to Programming */ /* By Dr. ANTF */ /* www.antf.net */ /* Copyright 2015 */ /* */ /* C# 320 - Problem 19: Summation 3 */ /******************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DOS { class Program { static void Main(string[] args) { int n, factorial, neg = 1, power; float sum = 0f; Console.Write("Please enter a number: "); n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { //get the power power = 1; for (int j = 0; j < i; j++) power = power * i; //get the factorial of i factorial = 1; for (int j = 1; j <= i; j++) factorial = factorial * j; factorial = factorial * neg; sum = sum + ((float)power / factorial); neg = neg * -1; } sum = sum + 1; Console.WriteLine("\n\nThe summation is: {0}", sum); Console.ReadKey(); } } }