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;
- using System.Threading;
- namespace Task1
- {
- class Program
- {
- static double Calc(double a1, double a2, double h)
- {
- double ans = 0;
- int i = 0;
- while (a1 + i * h < a2)
- {
- double p1 = Math.Sin(a1 + i * h) * Math.Cos(a1 + i * h) + Math.Cos(a1 + i * h);
- double p2;
- double h1 = h;
- if (a1 + i * h + h < a2)
- {
- p2 = Math.Sin(a1 + i * h + h) * Math.Cos(a1 + i * h + h) + Math.Cos(a1 + i * h + h);
- }
- else
- {
- p2 = Math.Sin(a2) * Math.Cos(a2) + Math.Cos(a2);
- h1 = (a2 - a1 + i * h);
- }
- if (p1 * p2 >= 0)
- {
- if (p1 < 0)
- {
- ans += Math.Max(p1, p2) * h1;
- ans -= (h1 * Math.Abs(p2 - p1)) / 2;
- }
- else
- {
- ans += Math.Min(p1, p2) * h1;
- ans += (h1 * Math.Abs(p2 - p1)) / 2;
- }
- }
- else
- {
- ans += (h1 * (p1)) / (2+2*p1/p2);
- ans += (h1 * (p2)) / (2+2*p2/p1);
- }
- i++;
- }
- return ans;
- }
- static void Main(string[] args)
- {
- double sum = -1;
- double a = 0, b = 0, h = 0;
- int N = 0;
- while (sum != 0)
- {
- Console.Write("Введите а= ");
- a = Double.Parse(Console.ReadLine());
- Console.Write("Введите b= ");
- b = Double.Parse(Console.ReadLine());
- if (b < a)
- {
- Console.WriteLine("Неправильно введен отрезок");
- sum = -1;
- }
- else sum = 0;
- }
- sum = -1;
- while (sum != 0)
- {
- Console.Write("Введите шаг h= ");
- h = Double.Parse(Console.ReadLine());
- if (h <= 0)
- {
- Console.WriteLine("Неправильно введен шаг");
- sum = -1;
- }
- else sum = 0;
- }
- sum = -1;
- while (sum != 0)
- {
- Console.Write("Введите N= ");
- N = Int32.Parse(Console.ReadLine());
- if (N <= 0)
- {
- Console.WriteLine("Неправильно введен N");
- sum = -1;
- }
- else sum = 0;
- }
- double ans = 0;
- Task<double>[] task = new Task<double>[N];
- double dx = (b - a) / N;
- for (int i = 0; i < N; i++)
- {
- task[i] = new Task<double>(() => Calc(a+dx*(i), a+dx*(i+1), h));
- task[i].Start();
- }
- for (int i = 0; i < N; i++)
- {
- ans += task[i].Result;
- }
- Console.Write("Ответ: ");
- Console.WriteLine(ans);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement