Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace VikaLab3
- {
- class Program
- { /// <summary>
- /// Метод контроля ввода
- /// </summary>
- /// <returns></returns>
- private static double Control()
- {
- string str = Console.ReadLine();
- double x;
- while (!double.TryParse(str, out x))
- {
- Console.WriteLine("Повторите ввод");
- str = Console.ReadLine();
- }
- return x;
- }
- private static double Ins()
- {
- double x = Control();
- while (x<-1 || x>=1)
- {
- Console.WriteLine("Значение должно быть от -1 включительно до 1. Повторите ввод");
- x = Control();
- }
- return x;
- }
- static void Main(string[] args)
- {
- bool a = true;
- while (a)
- {
- Console.WriteLine("Что вы хотите сделать? (1 - продолжить, 0 - выйти из программы)");
- string str = Console.ReadLine();
- switch (str)
- {
- case "1":
- try
- {
- Console.WriteLine("Введите начальное значение x");
- double x = Ins();
- Console.WriteLine("Введите конечное значение х");
- double xe = Ins();
- Console.WriteLine("Введите шаг");
- double dx = Ins();
- Console.WriteLine("Введите значение точности");
- double t = Ins();
- int n = 0; //число шагов (слагаемых)
- double ypr = 0;
- int k = (int)((xe - x) / dx);
- double yt;
- for (int i = 0; i <= k; i++)
- {
- n = 0;
- ypr = 0;
- while (Math.Abs((((Math.Pow(-1, n)) * Math.Pow(x, n + 1)) / (n + 1))) > t)
- {
- ypr += (((Math.Pow(-1, n)) * Math.Pow(x, n + 1)) / (n + 1));
- n++;
- }
- yt = Math.Log(x + 1);
- Console.WriteLine("\n");
- Console.WriteLine("________________________________________________");
- Console.WriteLine(" x || yt || ypr ");
- Console.WriteLine("________________________________________________");
- Console.Write(" {0} " + " {1} " + " {2} ", x, yt, ypr);
- Console.WriteLine("\n");
- Console.WriteLine("n = " + n);
- x += dx;
- }
- }
- catch
- {
- Console.WriteLine("Ошибка.");
- }
- Console.ReadKey();
- //Console.WriteLine("Повторите ввод");
- break;
- case "0":
- a = false;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement