Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Лаба_2
- {
- public static class function // класс функция
- {
- public static double Log(double x, double e, out int count)
- {
- double result1 = 0.0; int Count = 0; double result = 0.0;
- double d = x;
- double n = 1.0;
- double division = 0.0;
- do
- {
- division = (Math.Pow(d, n)) / n;
- result1 += division;
- d *= (x * x);
- n += 2; // степень (2n +1)
- Count++;
- result = 2 * result1;
- }
- while (Math.Abs(division) >= e);
- count = Count;
- return result;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Задайте значения: "); //ввод различных значений
- Console.Write("Xmin = ");
- double min = Convert.ToDouble(Console.ReadLine());
- Console.Write("Xmax = ");
- double max = Convert.ToDouble(Console.ReadLine());
- Console.Write("Шаг dx = ");
- double dx = Convert.ToDouble(Console.ReadLine());
- Console.Write("Точность e = ");
- double e = Convert.ToDouble(Console.ReadLine());
- //создание таблицы
- string a = " {0,10} | {1,10} | {2,10} |"; // таблица
- string b = string.Format(a, "x", "y", "N"); // название колонок
- Console.WriteLine(b);
- Console.WriteLine(new string('=', b.Length));
- for (double c = min; c <= max; c += dx) //цикл, помещающий в таблицу полученные значения до тех пор, пока условие верно
- {
- int N;
- double result = function.Log(c, e, out N);
- Console.WriteLine(" {0,10:F5} | {1,10:F5} | {2,10} |", c, result, N);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement