Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using static System.Math;
  7.  
  8. namespace laba3
  9. {
  10.     class Program
  11.     {
  12.         const double ex = 0.00001;
  13.  
  14.         public static double Add(double x, int n)
  15.         {
  16.             return ((Pow(x,(2*n+1)) ) / (2*n + 1));
  17.         }
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             string str;
  22.             Console.WriteLine("Запрос необходимых данных:");
  23.             Console.WriteLine(" * * * ");
  24.             Console.WriteLine("Введите x начальный ");
  25.             str = Console.ReadLine();
  26.             double x;
  27.             while (!double.TryParse(str, out x))
  28.             {
  29.                 Console.WriteLine("Неправильный формат ввода");
  30.                 Console.WriteLine("Введите x начальный ");
  31.                 str = Console.ReadLine();
  32.             }
  33.  
  34.             Console.WriteLine("Введите x конечный ");
  35.             str = Console.ReadLine();
  36.             double xk;
  37.             while (!double.TryParse(str, out xk))
  38.             {
  39.                 Console.WriteLine("Неправильный формат ввода");
  40.                 Console.WriteLine("Введите x конечный ");
  41.                 str = Console.ReadLine();
  42.             }
  43.  
  44.             Console.WriteLine("Введите шаг ");
  45.             str = Console.ReadLine();
  46.  
  47.             double dx;
  48.             while (!double.TryParse(str, out dx))
  49.             {
  50.                 Console.WriteLine("Неправильный формат ввода");
  51.                 Console.WriteLine("Введите шаг");
  52.                 str = Console.ReadLine();
  53.             }
  54.  
  55.             int kolvo = (int)((xk - x) / dx);
  56.             Console.WriteLine("Начинаю построение");
  57.             Console.WriteLine(" * * * ");
  58.             Console.WriteLine("| параметр х|Приближенный  y| Количество |  y  точный  |");
  59.  
  60.             double y, temp, sum = 0;
  61.             int n = 0;
  62.  
  63.             for (int i = 0; i < kolvo; i++)
  64.             {
  65.                 y = Log(((1+x)/(1-x)));
  66.                 n = 0;
  67.                 sum = 0;
  68.                 temp = Add(x, n);
  69.                
  70.                 while (Abs(temp) > ex)
  71.                 {
  72.                     sum += temp;
  73.                     n++;
  74.                     temp = Add(x, n);
  75.                 }
  76.                 Console.WriteLine("|   {0,5:f2}   |  {1,4:f6}     |  {2,6:f6}  |  {3,6:f6}  |", x,2* sum, n, y);
  77.                 x += dx;
  78.             }
  79.             Console.WriteLine("Построение завершено");
  80.             Console.ReadKey();
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement