Professional Documents
Culture Documents
лаб11
лаб11
Економіко-правничий коледж
Запоріжжя 2023
Мета роботи: вивчення базових особливостей проєктування та
програмування програмних засобів на базі паралельних обчислень
Математична модель:
( )
n
(− 1 )n x 2 n+1
∑
n=0 ( 2 n+1 ) !
class Program
{
static double sin_x = 0;
static int num_threads = 4;
static int num_iterations;
static double accuracy;
Console.WriteLine("Enter number - 1 if calculate sin with interations, 2 if calculate sin with accuracy: ");
int res = int.Parse(Console.ReadLine());
if (res == 1)
{
Console.WriteLine("Enter the number of iterations: ");
num_iterations = int.Parse(Console.ReadLine());
Console.WriteLine("Enter x: ");
int x = int.Parse(Console.ReadLine());
}
else
{
Console.WriteLine("Enter the accuracy: ");
accuracy = double.Parse(Console.ReadLine());
}
static void CalculateOddEven(object index)
{
int i = (int)index;
double x = GetUserInput();
for (int j = i + 1; j <= num_iterations; j += num_threads)
{
sin_x += Math.Pow(-1, j) * Math.Pow(x, 2*j+1) / Program.Factorial(2*j+1 );
}
}