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