Загрузка данных


Форма 





using System;
using System.Text;
using System.Windows.Forms;

namespace lr16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            try
            {
                double p = double.Parse(txtP.Text);
                double b = double.Parse(txtB.Text);
                double c = double.Parse(txtC.Text);
                int N = int.Parse(txtN.Text);
                int R = int.Parse(txtR.Text);

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Вариант: 14");
                sb.AppendLine();

                double Z = 0;

                if (radioSeries.Checked)
                {
                    sb.AppendLine("Метод 1: Сумма ряда");
                    sb.AppendLine("Члены ряда:");

                    double sum = 0;
                    int fact = 1;

                    for (int k = 2; k <= 5; k++)
                    {
                        fact *= k;
                        double term = Math.Pow(p, k) / fact;

                        if (k % 2 == 0)
                            term = -term;

                        sum += term;

                        sb.AppendLine($"Член {k-1}: {term:F6}");
                    }

                    Z = sum;
                }
                else
                {
                    sb.AppendLine("Метод 2: Двойная сумма");

                    double sum = 0;

                    for (int i = 1; i <= N; i++)
                    {
                        for (int j = 1; j <= R; j++)
                        {
                            double val = (Math.Pow(i, 2) + b * j) /
                                         (Math.Pow(c, i) * Math.Pow(j, 3));

                            sum += val;

                            sb.AppendLine($"i={i}, j={j} -> {val:F6}");
                        }
                    }

                    Z = sum;
                }

                sb.AppendLine();
                sb.AppendLine($"Z = {Z:F6}");

                txtResult.Text = sb.ToString();
            }
            catch
            {
                MessageBox.Show("Ошибка ввода!");
            }
        }
    }
}







Дизайнер
namespace lr16
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;

        private GroupBox groupInput;
        private GroupBox groupMethod;
        private TextBox txtP, txtB, txtC, txtN, txtR;
        private RadioButton radioSeries, radioSum;
        private Button btnCalc;
        private TextBox txtResult;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
                components.Dispose();
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.groupInput = new GroupBox();
            this.groupMethod = new GroupBox();
            this.txtP = new TextBox();
            this.txtB = new TextBox();
            this.txtC = new TextBox();
            this.txtN = new TextBox();
            this.txtR = new TextBox();
            this.radioSeries = new RadioButton();
            this.radioSum = new RadioButton();
            this.btnCalc = new Button();
            this.txtResult = new TextBox();

            this.SuspendLayout();

            // === Input Group ===
            groupInput.Text = "Исходные данные";
            groupInput.Location = new System.Drawing.Point(20, 20);
            groupInput.Size = new System.Drawing.Size(250, 180);

            txtP.Location = new System.Drawing.Point(20, 30);
            txtP.Text = "2";

            txtB.Location = new System.Drawing.Point(20, 60);
            txtB.Text = "1";

            txtC.Location = new System.Drawing.Point(20, 90);
            txtC.Text = "2";

            txtN.Location = new System.Drawing.Point(20, 120);
            txtN.Text = "5";

            txtR.Location = new System.Drawing.Point(20, 150);
            txtR.Text = "4";

            groupInput.Controls.AddRange(new Control[] { txtP, txtB, txtC, txtN, txtR });

            // === Method Group ===
            groupMethod.Text = "Метод расчёта";
            groupMethod.Location = new System.Drawing.Point(20, 210);
            groupMethod.Size = new System.Drawing.Size(250, 100);

            radioSeries.Text = "Метод 1 (ряд)";
            radioSeries.Location = new System.Drawing.Point(10, 30);
            radioSeries.Checked = true;

            radioSum.Text = "Метод 2 (сумма)";
            radioSum.Location = new System.Drawing.Point(10, 60);

            groupMethod.Controls.Add(radioSeries);
            groupMethod.Controls.Add(radioSum);

            // === Button ===
            btnCalc.Text = "Рассчитать";
            btnCalc.Location = new System.Drawing.Point(50, 320);
            btnCalc.Click += new System.EventHandler(btnCalc_Click);

            // === Result ===
            txtResult.Location = new System.Drawing.Point(300, 20);
            txtResult.Size = new System.Drawing.Size(350, 350);
            txtResult.Multiline = true;
            txtResult.ScrollBars = ScrollBars.Vertical;

            // === Form ===
            this.ClientSize = new System.Drawing.Size(680, 400);
            this.Controls.Add(groupInput);
            this.Controls.Add(groupMethod);
            this.Controls.Add(btnCalc);
            this.Controls.Add(txtResult);

            this.Text = "Вариант 14";

            this.ResumeLayout(false);
        }
    }
}






Программ



using System;

namespace lr16_console
{
    class Program
    {
        static void Main()
        {
            try
            {
                Console.WriteLine("=== Вариант 14 ===");

                // Ввод данных
                Console.Write("Введите p: ");
                double p = double.Parse(Console.ReadLine());

                Console.Write("Введите b: ");
                double b = double.Parse(Console.ReadLine());

                Console.Write("Введите c: ");
                double c = double.Parse(Console.ReadLine());

                Console.Write("Введите N: ");
                int N = int.Parse(Console.ReadLine());

                Console.Write("Введите R: ");
                int R = int.Parse(Console.ReadLine());

                Console.WriteLine();
                Console.WriteLine("Выберите метод:");
                Console.WriteLine("1 - Сумма ряда");
                Console.WriteLine("2 - Двойная сумма");

                int method = int.Parse(Console.ReadLine());

                double Z = 0;

                // ===== МЕТОД 1 =====
                if (method == 1)
                {
                    Console.WriteLine("\nМетод 1: Сумма ряда");
                    double sum = 0;
                    int fact = 1;

                    for (int k = 2; k <= 5; k++)
                    {
                        fact *= k;
                        double term = Math.Pow(p, k) / fact;

                        if (k % 2 == 0)
                            term = -term;

                        sum += term;

                        Console.WriteLine($"Член {k - 1}: {term:F6}");
                    }

                    Z = sum;
                }

                // ===== МЕТОД 2 =====
                else if (method == 2)
                {
                    Console.WriteLine("\nМетод 2: Двойная сумма");

                    double sum = 0;

                    for (int i = 1; i <= N; i++)
                    {
                        for (int j = 1; j <= R; j++)
                        {
                            double value = (Math.Pow(i, 2) + b * j) /
                                           (Math.Pow(c, i) * Math.Pow(j, 3));

                            sum += value;

                            Console.WriteLine($"i={i}, j={j} -> {value:F6}");
                        }
                    }

                    Z = sum;
                }
                else
                {
                    Console.WriteLine("Неверный выбор метода!");
                    return;
                }

                Console.WriteLine("\n=====================");
                Console.WriteLine($"Итог: Z = {Z:F6}");
                Console.WriteLine("=====================");

            }
            catch
            {
                Console.WriteLine("Ошибка ввода!");
            }

            Console.ReadKey();
        }
    }
}