Advertisement
TzvetanIG

Calculate 1 + 1!/X + 2!/X2 + … + N!/XN

Apr 13th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. class CalculatesTheSumS
  2. {
  3.     static void Main()
  4.     {
  5.         long n = long.Parse(Console.ReadLine());
  6.         long x = long.Parse(Console.ReadLine());
  7.         double sequenceMember = 1;
  8.         double sum = 1;
  9.  
  10.         for (int i = 1; i <= n; i++)
  11.         {
  12.             sequenceMember *= (double)i / x;
  13.             sum += sequenceMember;
  14.         }
  15.  
  16.         Console.WriteLine("{0:F5}",sum);
  17.      
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement