Advertisement
Dam4eeeg

Untitled

Apr 8th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace lr4
  11. {
  12.     public partial class SUmm : Form
  13.     {
  14.         public SUmm()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.  
  22.         }
  23.  
  24.         private void label2_Click(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         private void b1_Click(object sender, EventArgs e)
  30.         {
  31.             const double eps = 0.0001;
  32.             double x = Convert.ToDouble(tb1.Text);
  33.             double result = GetSeriesSum(x, eps);
  34.             l4.Text = Convert.ToString(result);
  35.         }
  36.         private static double GetSeriesSum(double x, double e)
  37.         {
  38.             int i = 1;
  39.             double sum = 0, y = 1, lastsum = double.MinValue;
  40.             while (Math.Abs(sum - lastsum) > e)
  41.             {
  42.                 lastsum = sum;
  43.                 sum += (y *= x / i++);
  44.             }
  45.             return sum;
  46.         }
  47.  
  48.     }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement