a
aaunknown
csharp
2 years ago
1.7 kB
22
Indexable
using System;
using System.Windows.Forms;
namespace _17_april
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0)
{
MessageBox.Show("Введите требуемые значения!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
double x = double.Parse(textBox1.Text.Replace(".", ","));
double epsilon = double.Parse(textBox2.Text.Replace(".", ","));
listBox1.Items.Clear();
double term;
int iteration = 1;
do
{
term = Math.Pow(x, iteration) / Factorial(iteration) * Math.Pow(-1, iteration - 1);
if (Math.Abs(term) > epsilon)
{
listBox1.Items.Add($"{iteration,-10} {x,-20:F10} {term,-20:F10}");
}
iteration++;
} while (Math.Abs(term) > epsilon);
textBox3.Text = (iteration - 1).ToString();
textBox4.Text = term.ToString("F10");
}
}
private double Factorial(int n)
{
if (n == 0) return 1;
double result = 1;
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}Editor is loading...
Leave a Comment