dxnge

Untitled

Oct 9th, 2022
841
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 1 0
  1. using System;
  2.  
  3. namespace ConsoleApp6
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int Factorial(int n)
  10.             {
  11.                 if (n == 1) return 1;
  12.                 if (n == 0) return 1;
  13.  
  14.                 return n * Factorial(n - 1);
  15.             }
  16.  
  17.             double lim = 0.0001, abs_sum = 0, cur_n = double.PositiveInfinity;
  18.             int i = 0;
  19.             while(cur_n >= lim)
  20.             {
  21.                 double cur_sum = 0;
  22.                 for (double x = 0.1; x <= 1; x += 0.05)
  23.                 {
  24.                     double up = 1, dn = 1;
  25.                    
  26.                     for (int n = 0; n < i; n++)
  27.                     {
  28.                         up *= 2 * x;
  29.                     }
  30.  
  31.                     dn = Factorial(i);
  32.  
  33.                     cur_sum += up / dn;
  34.  
  35.                     Console.WriteLine($"y == {Math.Pow(Math.E, 2*x)}");
  36.                 }
  37.                 if (cur_sum >= lim)
  38.                 {
  39.                     abs_sum += cur_sum;
  40.                     i++;
  41.                 }
  42.  
  43.                 cur_n = cur_sum;
  44.             }
  45.             Console.WriteLine($"\ns = {abs_sum} {i}");
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment