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 Całka_sposób3
- {
- class Program
- {
- class Całka
- {
- private readonly object zamek = new object();
- double dx;
- double wynik = 0;
- public Całka(double dx)
- {
- this.dx = dx;
- }
- public void LiczenieCałka()
- {
- double temp = 0;
- for (double x = 1; x <= 10; x = x + dx)
- {
- temp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
- }
- temp *= dx;
- lock (zamek)
- {
- wynik += temp;
- }
- }
- public void LiczenieCałka2()
- {
- double tempp = 0;
- for (double x = 10; x <= 20; x = x + dx)
- {
- tempp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
- }
- tempp *= dx;
- lock (zamek)
- {
- wynik += tempp;
- }
- }
- public void LiczenieCałka3()
- {
- double temmp = 0;
- for (double x = 20; x <= 30; x = x + dx)
- {
- temmp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
- }
- temmp *= dx;
- lock (zamek)
- {
- wynik += temmp;
- }
- }
- public void LiczenieCałka4()
- {
- double temp = 0;
- for (double x = 30; x <= 40; x = x + dx)
- {
- temp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
- }
- temp*= dx;
- lock (zamek)
- {
- wynik += temp;
- }
- }
- public void Wyświetlwynik()
- {
- Console.WriteLine(wynik);
- }
- }
- static void Main(string[] args)
- {
- Całka c = new Całka(0.001);
- Thread t = new Thread(new ThreadStart(c.LiczenieCałka));
- Thread th = new Thread(new ThreadStart(c.LiczenieCałka2));
- Thread thr = new Thread(new ThreadStart(c.LiczenieCałka3));
- Thread thrd = new Thread(new ThreadStart(c.LiczenieCałka4));
- t.Start();
- th.Start();
- thr.Start();
- thrd.Start();
- c.Wyświetlwynik();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement