12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp6
- {
- public partial class Lab1 : Form
- {
- public static bool Active;
- public Lab1()
- {
- InitializeComponent();
- }
- private void Lab1_Load(object sender, EventArgs e)
- {
- Active = true;
- }
- private void Lab1_FormClosed(object sender, FormClosedEventArgs e)
- {
- Active = false;
- }
- private void btnCalculate_Click(object sender, EventArgs ef)
- {
- try
- {
- MessageBox.Show($"Ответ: {Calculate(int.Parse(tbInputK.Text))}", "Ответ");
- } catch
- {
- MessageBox.Show($"Не верно заполнено поле", "Ошибка");
- }
- }
- static double Calculate(int num)
- {
- int k = num;
- double Sum = 0;
- double e = 0.001;
- while (true)
- {
- double term = Math.Pow(-1, k + 1) / (2 * k - 1);
- Sum += term;
- if (Math.Abs(term) < e)
- {
- break;
- }
- k++;
- }
- double piOver4 = Sum;
- double pi = piOver4 * 4;
- double roundedpiOver4 = Math.Round(piOver4, 5);
- return roundedpiOver4;
- }
- public string MessagePull()
- {
- string message = $"Lab1 | Число K: {tbInputK.Text}";
- return message;
- }
- }
- }
|