Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that, for a given two integer numbers n and x, calculates the sum S = 1 + 1!/x + 2!/x2 + … + n!/xn. Use only one loop.
- //Print the result with 5 digits after the decimal point.
- class CalculateEquation
- {
- static void Main()
- {
- Console.Write("N = ");
- int n = int.Parse(Console.ReadLine());
- Console.Write("X = ");
- int x = int.Parse(Console.ReadLine());
- int fakN = 1;
- int powX = 1;
- double sum = 1;
- for (int i = 1; i <= n; i++)
- {
- powX *= x;
- fakN *= i;
- sum += ((double)fakN / powX);
- }
- Console.WriteLine("sum = {0:F5}",sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement