Фрагмент
: Calculator.cs
public class Calculator { private int[] array; public Calculator(int[] Array)
{ this.array = Array;
} public void Sum()
{ int sum = 0; for (int i = 0; i < array.Length; i++)
{
Console.WriteLine($"Sum of elements from 0 to {i} = {sum}"); sum += array[i];
Thread.Sleep(500);
}
} public void Product()
{ int product = 1; for (int i = 0; i < array.Length; i++)
{
Console.WriteLine($"Product of elements from 0 to {i} = {product}"); product *= array[i];
Thread.Sleep(500);
}
}
}
Program.cs
public class Program { static void Main(string[] args)
{ int arraySize = int.Parse(Console.ReadLine()); int[] array = new int[arraySize];
Random random = new Random(); for (int i = 0; i < arraySize; i++)
{ array[i] = random.Next(-100, 100);
}
Console.WriteLine($"Array: {String.Join(",", array)}");
Calculator calculator = new Calculator(array);
Thread sumThread = new Thread(calculator.Sum);
Thread productThread = new Thread(calculator.Product);
}
}
Сподели с приятели: