Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 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.  
  7. namespace VikaLab3
  8. {
  9. class Program
  10. { /// <summary>
  11. /// Метод контроля ввода
  12. /// </summary>
  13. /// <returns></returns>
  14. private static double Control()
  15. {
  16. string str = Console.ReadLine();
  17. double x;
  18. while (!double.TryParse(str, out x))
  19. {
  20. Console.WriteLine("Повторите ввод");
  21. str = Console.ReadLine();
  22. }
  23. return x;
  24. }
  25. private static double Ins()
  26. {
  27. double x = Control();
  28. while (x<-1 || x>=1)
  29. {
  30. Console.WriteLine("Значение должно быть от -1 включительно до 1. Повторите ввод");
  31. x = Control();
  32. }
  33. return x;
  34. }
  35.  
  36.  
  37. static void Main(string[] args)
  38. {
  39. bool a = true;
  40. while (a)
  41. {
  42. Console.WriteLine("Что вы хотите сделать? (1 - продолжить, 0 - выйти из программы)");
  43. string str = Console.ReadLine();
  44. switch (str)
  45. {
  46. case "1":
  47. try
  48. {
  49. Console.WriteLine("Введите начальное значение x");
  50. double x = Ins();
  51. Console.WriteLine("Введите конечное значение х");
  52. double xe = Ins();
  53. Console.WriteLine("Введите шаг");
  54. double dx = Ins();
  55. Console.WriteLine("Введите значение точности");
  56. double t = Ins();
  57. int n = 0; //число шагов (слагаемых)
  58. double ypr = 0;
  59. int k = (int)((xe - x) / dx);
  60. double yt;
  61. for (int i = 0; i <= k; i++)
  62. {
  63. n = 0;
  64. ypr = 0;
  65.  
  66. while (Math.Abs((((Math.Pow(-1, n)) * Math.Pow(x, n + 1)) / (n + 1))) > t)
  67. {
  68. ypr += (((Math.Pow(-1, n)) * Math.Pow(x, n + 1)) / (n + 1));
  69. n++;
  70. }
  71. yt = Math.Log(x + 1);
  72. Console.WriteLine("\n");
  73. Console.WriteLine("________________________________________________");
  74. Console.WriteLine(" x || yt || ypr ");
  75. Console.WriteLine("________________________________________________");
  76. Console.Write(" {0} " + " {1} " + " {2} ", x, yt, ypr);
  77. Console.WriteLine("\n");
  78. Console.WriteLine("n = " + n);
  79. x += dx;
  80. }
  81. }
  82. catch
  83. {
  84. Console.WriteLine("Ошибка.");
  85. }
  86. Console.ReadKey();
  87. //Console.WriteLine("Повторите ввод");
  88. break;
  89. case "0":
  90. a = false;
  91. break;
  92. }
  93.  
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement