Untitled

mail@pastecode.io avatar
unknown
csharp
2 months ago
1.2 kB
1
Indexable
Never
using System;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Введите X: ");
            double X = double.Parse(Console.ReadLine());

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

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

            double p = 0;
            int znak = -1;

            for (int i = 1; i <= N; i++)
            {
                long fact = 1;
                for (int j = 1; j <= (2 * i - 1); j++)
                {
                    fact *= j;
                }

                if (i % 2 != 0)
                {
                    p += Math.Pow(X, 2 * i - 1) / fact * znak;
                    znak *= -1;
                }
                else
                {
                    p += Math.Pow(Y, 2 * i - 1) / fact * znak;
                    znak *= -1;
                }
            }

            Console.WriteLine($"Результат: {Math.Round(p, 2)}");
        }
    }
}
Leave a Comment