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


public partial class Form1 : Form
{
    double[] A = new double[25];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 25; i++)
        {
            A[i] = rand.Next(-5, 6) + rand.NextDouble();
            listBox1.Items.Add("A[" + i + "] = " + A[i].ToString("F2"));
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        int negativeCount = 0;
        int rangeCount = 0;

        for (int i = 0; i < 25; i++)
        {
            if (A[i] < 0)
                negativeCount++;
            if (A[i] >= 1 && A[i] <= 2)
                rangeCount++;
        }

        listBox2.Items.Add("Количество отрицательных: " + negativeCount);
        listBox2.Items.Add("Количество элементов в [1,2]: " + rangeCount);
    }
}

public partial class Form1 : Form
{
    int[] Z = new int[35];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 35; i++)
        {
            Z[i] = rand.Next(-5, 11);
            listBox1.Items.Add("Z[" + i + "] = " + Z[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        int S = 0;
        long P = 1;
        bool foundOdd = false;

        for (int i = 0; i < 35; i++)
        {
            if (Z[i] % 2 == 0 && Z[i] < 3)
                S += Z[i];

            if (Z[i] % 2 != 0 && Z[i] > 1)
            {
                P *= Z[i];
                foundOdd = true;
            }
        }

        if (!foundOdd) P = 0;
        long R = S + P;

        listBox2.Items.Add("S (сумма чётных < 3) = " + S);
        listBox2.Items.Add("P (произведение нечётных > 1) = " + P);
        listBox2.Items.Add("R = S + P = " + R);
    }
}

public partial class Form1 : Form
{
    int[] Q = new int[20];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 20; i++)
        {
            Q[i] = rand.Next(1, 101);
            listBox1.Items.Add("Q[" + i + "] = " + Q[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        listBox2.Items.Add("Элементы с остатком 1, 2 или 5 при делении на 7:");

        for (int i = 0; i < 20; i++)
        {
            int remainder = Q[i] % 7;
            if (remainder == 1 || remainder == 2 || remainder == 5)
                listBox2.Items.Add("Q[" + i + "] = " + Q[i] +
                                   " (остаток: " + remainder + ")");
        }
    }
}

public partial class Form1 : Form
{
    int[] Mas = new int[10];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 10; i++)
        {
            Mas[i] = rand.Next(-20, 20);
            listBox1.Items.Add("Mas[" + i + "] = " + Mas[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();

        // Ищем индекс первого отрицательного элемента
        int firstNegIndex = -1;
        for (int i = 0; i < 10; i++)
        {
            if (Mas[i] < 0)
            {
                firstNegIndex = i;
                break;
            }
        }

        if (firstNegIndex == -1 || firstNegIndex == 9)
        {
            listBox2.Items.Add("Нет отрицательных или нет элементов после него");
            return;
        }

        long product = 1;
        listBox2.Items.Add("Первый отрицательный: Mas[" + firstNegIndex + "] = "
                           + Mas[firstNegIndex]);
        listBox2.Items.Add("Элементы после него:");

        for (int i = firstNegIndex + 1; i < 10; i++)
        {
            product *= Mas[i];
            listBox2.Items.Add("Mas[" + i + "] = " + Mas[i]);
        }

        listBox2.Items.Add("Произведение = " + product);
    }
}

public partial class Form1 : Form
{
    int[] Mas = new int[14];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 14; i++)
        {
            Mas[i] = rand.Next(-20, 20);
            listBox1.Items.Add("Mas[" + i + "] = " + Mas[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        int sum = 0;
        int firstNegIndex = -1;

        for (int i = 0; i < 14; i++)
        {
            if (Mas[i] < 0)
            {
                firstNegIndex = i;
                break;
            }
            sum += Mas[i];
            listBox2.Items.Add("Mas[" + i + "] = " + Mas[i]);
        }

        if (firstNegIndex == -1)
            listBox2.Items.Add("Отрицательных элементов нет");
        else if (firstNegIndex == 0)
            listBox2.Items.Add("Первый элемент отрицательный, сумма = 0");
        else
        {
            listBox2.Items.Add("Первый отрицательный: Mas[" + firstNegIndex + "] = "
                               + Mas[firstNegIndex]);
            listBox2.Items.Add("Сумма до него = " + sum);
        }
    }
}

public partial class Form1 : Form
{
    int[] Mas = new int[12];

    public Form1() { InitializeComponent(); }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        listBox2.Items.Clear();
        Random rand = new Random();
        for (int i = 0; i < 12; i++)
        {
            Mas[i] = rand.Next(-30, 30);
            listBox1.Items.Add("Mas[" + i + "] = " + Mas[i]);
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        int sum = 0;

        for (int i = 0; i < 12; i++)
        {
            if (Mas[i] % 2 == 0)
            {
                sum += Mas[i];
                listBox2.Items.Add("Mas[" + i + "] = " + Mas[i]);
            }
        }

        listBox2.Items.Add("Сумма чётных элементов = " + sum);
    }
}