Advertisement
dim4o

Loops_05_CalculateSum

Mar 26th, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             int n = int.Parse(Console.ReadLine());
  4.             int x = int.Parse(Console.ReadLine());
  5.             float sum = 1;
  6.             float factorial = 1;
  7.             int power = x;
  8.             for (int count = 1; count <= n; count++)
  9.             {
  10.                 factorial *= count;
  11.                 sum += factorial / x;
  12.                 Console.WriteLine(sum);
  13.                 x *= power;
  14.             }
  15.             Console.WriteLine("{0 :F5}", sum);
  16.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement