Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class SumXn
- {
- static void Main()
- {
- Console.WriteLine("Please enter integer x:");
- int x = int.Parse(Console.ReadLine());
- Console.WriteLine("Please enter positive integer n:");
- int n = int.Parse(Console.ReadLine());
- decimal productNFactorial = 1m;
- decimal xPowerN = 1m;
- decimal sumxN = 1m;
- if (n >= 0) // factorial could be calculated from positive integer only. 0!=1
- {
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= i; j++)
- {
- productNFactorial = (productNFactorial * j);
- }
- xPowerN = xPowerN * x;
- sumxN = sumxN + (productNFactorial / xPowerN);
- productNFactorial = 1m;
- }
- Console.WriteLine("The result is: {0}", sumxN);
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement