Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_G
  8. {
  9. class Program
  10. {
  11. public static void Term (int N, ref double Sum)
  12. {
  13. Sum = 1;
  14. double fact = 1;
  15. for (int i = 1; i <= N; i++)
  16. {
  17. fact = fact*(1.0/i);
  18. if (Sum.Equals(double.PositiveInfinity))
  19. Console.WriteLine(5);
  20. Sum += fact;
  21. }
  22. }
  23. static void Main(string[] args)
  24. {
  25. double Sum=1;
  26. int N;
  27. if (!int.TryParse(Console.ReadLine(), out N) || (N<1))
  28. Console.WriteLine("wrong");
  29. else
  30. {
  31. Term(N, ref Sum);
  32. Console.WriteLine(Math.Round(Sum, 5));
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement