Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Threading;
- namespace ConsoleApp1
- {
- class ConsoleApp1
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите кол-во строк: ");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите кол-во столбцов: ");
- int m = Convert.ToInt32(Console.ReadLine());
- double N = 0;
- double t1 = 0, t2 = 0, t3 = 0, t4 = 0;
- double s=0;
- var timer = Stopwatch.StartNew();
- void FirstThread()
- {
- for (int i = 1; i < (((n ) / 4) + 1); i++)
- {
- s = 0;
- for (int j = 1; j < m + 1; j++)
- {
- s = Math.Sqrt((i-1)+(j-1));
- t1 += s;
- }
- }
- }
- void SecondThread()
- {
- for (int i = (((n) / 4) + 1); i < ((n) / 2) + 1; i++)
- {
- s = 0;
- for (int j = 1; j < m + 1; j++)
- {
- s = Math.Sqrt((i-1)+(j-1));
- t2 += s;
- }
- }
- }
- void ThirdThread()
- {
- for (int i = ((n) / 2) + 1; i < ((3 * (n)) / 4) + 1; i++)
- {
- s = 0;
- for (int j = 1; j < m + 1; j++)
- {
- s = Math.Sqrt((i-1)+(j-1));
- t3 += s;
- }
- }
- }
- void FourthThread()
- {
- for (int i = (3 * (n)) / 4 + 1; i < (n + 1); i++)
- {
- s = 0;
- for (int j = 1; j < m + 1; j++)
- {
- s = Math.Sqrt((i-1)+(j-1));
- t4 += s;
- }
- }
- }
- Thread thr1 = new Thread(() => FirstThread());
- Thread thr2 = new Thread(() => SecondThread());
- Thread thr3 = new Thread(() => ThirdThread());
- Thread thr4 = new Thread(() => FourthThread());
- thr1.Start();
- Thread.Sleep(100);
- thr2.Start();
- Thread.Sleep(100);
- thr3.Start();
- Thread.Sleep(100);
- thr4.Start();
- Thread.Sleep(100);
- N = t1 * t2 * t3 * t4;
- Console.WriteLine("Результат - " + (N - N % 0.001));
- timer.Stop();
- Console.WriteLine("Выполнение метода заняло мс: {0}", timer.ElapsedMilliseconds - 400);
- Console.WriteLine("Выполнение метода заняло тактов: {0}", timer.ElapsedTicks-400000);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment