/******************************************************/ /* Introduction to Programming */ /* By Dr. ANTF */ /* www.antf.net */ /* Copyright 2015 */ /* */ /* C# 319 - Problem 18: Summation 2 (b) */ /******************************************************/ 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; float sum = 0f; Console.Write("Please enter a number: "); n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { //get the factorial of i factorial = 1; for (int j = 1; j <= i; j++) factorial = factorial * j; //get the sum if (i % 2 == 1) sum = sum + ((float)i / factorial); else sum = sum - ((float)i / factorial); } sum = sum + 1; Console.WriteLine("\n\nThe summation is: {0}", sum); Console.ReadKey(); } } }