Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7.     class Program
  8.     {
  9.     static double answer(long n) {
  10.         double result = 1;
  11.         double m = 1.0;
  12.         long b = 2;
  13.         while (n > 0)
  14.         {
  15.             result = result + (1 / m);
  16.             m *= b;
  17.             b += 1;
  18.             n = n - 1;
  19.         }
  20.         return result;
  21.     }
  22.         static void Main()
  23.         {
  24.  
  25.         long n;
  26.        
  27.         string input = Console.ReadLine();
  28.         if (!long.TryParse(input, out n))
  29.         {
  30.             Console.WriteLine("wrong");
  31.         }
  32.         else {
  33.             Console.WriteLine($"{answer(n):0.00000}");
  34.             Console.ReadLine();
  35.         }
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement