Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 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 System.Threading;
  7.  
  8. namespace Task1
  9. {
  10. class Program
  11. {
  12. static double Calc(double a1, double a2, double h)
  13. {
  14. double ans = 0;
  15. int i = 0;
  16.  
  17. while (a1 + i * h < a2)
  18. {
  19. double p1 = Math.Sin(a1 + i * h) * Math.Cos(a1 + i * h) + Math.Cos(a1 + i * h);
  20. double p2;
  21. double h1 = h;
  22. if (a1 + i * h + h < a2)
  23. {
  24. p2 = Math.Sin(a1 + i * h + h) * Math.Cos(a1 + i * h + h) + Math.Cos(a1 + i * h + h);
  25. }
  26. else
  27. {
  28. p2 = Math.Sin(a2) * Math.Cos(a2) + Math.Cos(a2);
  29. h1 = (a2 - a1 + i * h);
  30. }
  31. if (p1 * p2 >= 0)
  32. {
  33. if (p1 < 0)
  34. {
  35. ans += Math.Max(p1, p2) * h1;
  36. ans -= (h1 * Math.Abs(p2 - p1)) / 2;
  37. }
  38. else
  39. {
  40. ans += Math.Min(p1, p2) * h1;
  41. ans += (h1 * Math.Abs(p2 - p1)) / 2;
  42. }
  43. }
  44. else
  45. {
  46. ans += (h1 * (p1)) / (2+2*p1/p2);
  47. ans += (h1 * (p2)) / (2+2*p2/p1);
  48. }
  49. i++;
  50. }
  51.  
  52. return ans;
  53. }
  54.  
  55. static void Main(string[] args)
  56. {
  57. double sum = -1;
  58. double a = 0, b = 0, h = 0;
  59. int N = 0;
  60. while (sum != 0)
  61. {
  62. Console.Write("Введите а= ");
  63. a = Double.Parse(Console.ReadLine());
  64. Console.Write("Введите b= ");
  65. b = Double.Parse(Console.ReadLine());
  66. if (b < a)
  67. {
  68. Console.WriteLine("Неправильно введен отрезок");
  69. sum = -1;
  70. }
  71. else sum = 0;
  72. }
  73. sum = -1;
  74. while (sum != 0)
  75. {
  76. Console.Write("Введите шаг h= ");
  77. h = Double.Parse(Console.ReadLine());
  78. if (h <= 0)
  79. {
  80. Console.WriteLine("Неправильно введен шаг");
  81. sum = -1;
  82. }
  83. else sum = 0;
  84. }
  85. sum = -1;
  86. while (sum != 0)
  87. {
  88. Console.Write("Введите N= ");
  89. N = Int32.Parse(Console.ReadLine());
  90. if (N <= 0)
  91. {
  92.  
  93. Console.WriteLine("Неправильно введен N");
  94. sum = -1;
  95. }
  96. else sum = 0;
  97. }
  98. double ans = 0;
  99. Task<double>[] task = new Task<double>[N];
  100. double dx = (b - a) / N;
  101. for (int i = 0; i < N; i++)
  102. {
  103. task[i] = new Task<double>(() => Calc(a+dx*(i), a+dx*(i+1), h));
  104. task[i].Start();
  105. }
  106. for (int i = 0; i < N; i++)
  107. {
  108. ans += task[i].Result;
  109. }
  110. Console.Write("Ответ: ");
  111. Console.WriteLine(ans);
  112. Console.ReadKey();
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement