P
P
Parsifal1122020-11-22 20:55:19
C++ / C#
Parsifal112, 2020-11-22 20:55:19

How to solve an example to solve a function without the math method. C#?

5fbaa575bfabd517136236.png
It is necessary to solve using For
here is the solution of a similar 3rd task

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp18
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.Write("x= ");
      double x = Convert.ToDouble(Console.ReadLine());
      Console.Write("n= ");
      int n = Convert.ToInt32(Console.ReadLine());
      if (n > 0)
      {
        double p = 0;
        for (int i = 1; i <= n; i++)
        {
        double a = 1;
        for (int o = 0; o < i; o++)
        {
        a = a * (-1);
        }
        int g = 1;
        for (int f = 1; f <= 2 * i; f++)
        {
        g = f * g;
        }
        double a1 = 1;
        for (int o = 0; o < 2 * i; o++)
        {
        a1 = a1 * x;
        }
        p = (a * a1 / g) + p;
        }
        double s = 1 + p;
        double perev = Math.Cos(x);
        Console.WriteLine("Задана функцiя= " + s);
        Console.WriteLine("Перевірочна функцiя= " + perev);
        Console.WriteLine("Похибка= " + (perev - s));
      }
        else
        Console.WriteLine("Error");
        Console.ReadLine();
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-22
@Parsifal112

where P is the product of all numbers. Where Sigma is the sum of all numbers.
n above the sum - the maximum value of the counter. i = ... - the initial value of the counter. "!" is the factorial.
Find out for yourself next. This is a site with answers to questions, not solutions to problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question