Facebook
From zd7, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 306
  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 ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         static int rozmiar = 10;
  13.         static double[] tab = new double[rozmiar];
  14.         static double[] tab1 = new double[rozmiar];
  15.  
  16.         static public void znajdz_max()
  17.         {
  18.  
  19.             int x = int.Parse(Thread.CurrentThread.Name);
  20.             double poprzedni, maks, nastepny, y = (double)x + 1;
  21.             maks = funkcja(y);
  22.             nastepny = funkcja(y + tab1[x]);
  23.             poprzedni = funkcja(y - tab1[x]);
  24.             do
  25.             {
  26.                 nastepny = funkcja(y + tab1[x]);
  27.  
  28.                 if (maks <= nastepny)
  29.                 {
  30.                     poprzedni = maks;
  31.                     maks = nastepny;
  32.                 }
  33.                 else if (maks <= poprzedni)
  34.                 {
  35.                     nastepny = maks;
  36.                     maks = poprzedni;
  37.                     tab1[x] *= (-1);
  38.                 }
  39.  
  40.             } while (maks > nastepny && maks > poprzedni);
  41.             tab[x] = maks;
  42.         }
  43.  
  44.         static double funkcja(double x)
  45.         {
  46.  
  47.             return Math.Log(x) * (Math.Sin(x) * Math.Sin(x) + Math.Sin(10 * x) * Math.Sin(10 * x));
  48.         }
  49.      
  50.         static void Main(string[] args)
  51.         {
  52.             Thread[] tabThread = new Thread[rozmiar];
  53.  
  54.             for (int i = 0; i < rozmiar; i++)
  55.             {
  56.                 tab1[i] = 0.01;
  57.             }
  58.  
  59.             for (int i = 0; i < rozmiar; i++)
  60.                 tabThread[i] = new Thread(new ThreadStart(znajdz_max));
  61.  
  62.             for (int i = 0; i < rozmiar; i++)
  63.             {
  64.                 tabThread[i].Name = i.ToString();
  65.                 tabThread[i].Start();
  66.             }
  67.             for (int i = 0; i < rozmiar; i++)
  68.             {
  69.                 Console.WriteLine(i + ".  " + tab[i]);
  70.             }  
  71.         }
  72.     }
  73. }