Untitled
unknown
csharp
3 years ago
757 B
4
Indexable
using System;
using System.Threading;
class Program {
static void Main(string[] args) {
int number = 5;
long factorial = 1;
Thread[] threads = new Thread[number];
for (int i = 0; i < number; i++) {
int j = i + 1;
threads[i] = new Thread(() => {
long result = 1;
for (int k = 1; k <= j; k++) {
result *= k;
}
Interlocked.Multiply(ref factorial, result);
});
threads[i].Start();
}
foreach (var thread in threads) {
thread.Join();
}
Console.WriteLine("Factorial: " + factorial);
Console.ReadLine();
}
}
Editor is loading...