Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 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. namespace Całka_sposób3
  8. {
  9. class Program
  10. {
  11.  
  12. class Całka
  13. {
  14. private readonly object zamek = new object();
  15. double dx;
  16. double wynik = 0;
  17. public Całka(double dx)
  18. {
  19. this.dx = dx;
  20. }
  21. public void LiczenieCałka()
  22. {
  23. double temp = 0;
  24. for (double x = 1; x <= 10; x = x + dx)
  25. {
  26. temp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
  27. }
  28. temp *= dx;
  29. lock (zamek)
  30. {
  31. wynik += temp;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. }
  39. public void LiczenieCałka2()
  40. {
  41. double tempp = 0;
  42. for (double x = 10; x <= 20; x = x + dx)
  43. {
  44. tempp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
  45. }
  46. tempp *= dx;
  47. lock (zamek)
  48. {
  49. wynik += tempp;
  50. }
  51.  
  52.  
  53.  
  54. }
  55. public void LiczenieCałka3()
  56. {
  57. double temmp = 0;
  58. for (double x = 20; x <= 30; x = x + dx)
  59. {
  60. temmp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
  61. }
  62. temmp *= dx;
  63. lock (zamek)
  64. {
  65. wynik += temmp;
  66. }
  67.  
  68.  
  69.  
  70.  
  71. }
  72. public void LiczenieCałka4()
  73. {
  74. double temp = 0;
  75. for (double x = 30; x <= 40; x = x + dx)
  76. {
  77. temp += 3 * Math.Pow(x, 3) + Math.Cos(7 * x) - Math.Log(2 * x);
  78. }
  79. temp*= dx;
  80. lock (zamek)
  81. {
  82. wynik += temp;
  83. }
  84.  
  85.  
  86.  
  87. }
  88. public void Wyświetlwynik()
  89. {
  90. Console.WriteLine(wynik);
  91. }
  92. }
  93. static void Main(string[] args)
  94. {
  95. Całka c = new Całka(0.001);
  96. Thread t = new Thread(new ThreadStart(c.LiczenieCałka));
  97. Thread th = new Thread(new ThreadStart(c.LiczenieCałka2));
  98. Thread thr = new Thread(new ThreadStart(c.LiczenieCałka3));
  99. Thread thrd = new Thread(new ThreadStart(c.LiczenieCałka4));
  100.  
  101. t.Start();
  102. th.Start();
  103.  
  104. thr.Start();
  105.  
  106. thrd.Start();
  107.  
  108. c.Wyświetlwynik();
  109. Console.ReadKey();
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement