Guest User

Untitled

a guest
Apr 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Task06_Sum
  7. {
  8.     class Sum
  9.     {
  10.         public static int Factorial(int input)
  11.         {
  12.             int factorial = 1;
  13.             for (int i = 1; i <= input; i++)
  14.             {
  15.                 factorial *= i;
  16.             }
  17.             return factorial;
  18.         }
  19.         public static void Main()
  20.         {
  21.             Console.Write("Enter N: ");
  22.             uint n = uint.Parse(Console.ReadLine());
  23.             Console.Write("Enter X: ");
  24.             int x = int.Parse(Console.ReadLine());
  25.             double sum = 1;
  26.             for (int i = 1; i <= n; i++)
  27.             {
  28.                 sum += Factorial(i) / Math.Pow(x, i);
  29.             }
  30.             Console.WriteLine("The sum is: " + sum);
  31.             Console.WriteLine("Press any key to continue");
  32.             Console.Read();
  33.         }
  34.     }
  35. }
Add Comment
Please, Sign In to add comment