Advertisement
Masovski

[C# Basics][Loops-HW] 5. Calculate 1 + N!/X^N

Mar 29th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using System;
  2.  
  3. class CalculateUglyFormula
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter n: ");
  8.         double n = double.Parse(Console.ReadLine());
  9.         Console.Write("Enter x: ");
  10.         double x = double.Parse(Console.ReadLine());
  11.  
  12.         double factorial = 1;
  13.         double result = 1;
  14.  
  15.         for (int i = 1; i <= n; i++)
  16.         {
  17.             factorial *= i;
  18.             result += factorial / Math.Pow(x, i);
  19.         }
  20.        
  21.         Console.WriteLine("{0:0.00000}", result);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement