Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c# program that ask a user for a whole number and prints out the factori

ID: 3841271 • Letter: W

Question

Write a c# program that ask a user for a whole number and prints out the factorial of that number. The program should use three threads (or tasks) to complete the computation. one thread should compute the factorial up to the first third, and the second should compute up to the middle third, and the third thread computed the factorial up to last thread. A final thread multiplies all three results to get final answer.

factorial of that write a ca program that asks a user for a whale number and prints out the number. The program should use three threads (or tasks) to complete the computation. One thread camputes the factorial upto first third, the second thread should compute the factorial of the middle third, and the third thread camputes factorial of the last A final thread multiplies all three results third, 25 divided into three to get the final answer For example, to compute 25 approximately equal parts H 9 Thread 1 (or Task Result 1 2 3 4 5"6"7" Thread2 (or Task2): Result2 w 9 10 11 12 13 14 15'16 Threada (or Task3) Resulta 17 18 19 20 21'22 23 24 25 Final result (Thread/Task4) Resulti'Resultz'Resulta Print Final result, Compare the result ofeomputing the factorial by using a sequential loop and printing the answer Which method is faster? How did you determine which method is faster?

Explanation / Answer

using System;
using System.Threading;

public class Work
{
public static int res = 1;
public static void Main()
{
Console.WriteLine("Enter number:");
int num = Convert.ToInt32(Console.ReadLine());
int> // Start a thread that calls a parameterized static method.
Thread newThread = new Thread(Work.ThreadA);
newThread.Start(num);

// Start a thread that calls a parameterized instance method.
Work w = new Work();
newThread = new Thread(w.ThreadB);
newThread.Start(num);
newThread = new Thread(w.ThreadC);
newThread.Start(num);
  
}

public static void ThreadA(object data)
{

int num = (int) data;
int>   
for (int i=1; i<=oneThird; i++)
{
  
res = res * i;
  
}
Console.WriteLine("Thread A "+res);
  
}

public void ThreadB(object data)
{
int num = (int) data;
int> int secondOneThird = 2 * oneThird;
for (int i=oneThird+1; i<=secondOneThird; i++)
{
res = res * i;
  
}
Console.WriteLine("Thread B "+res);
}
  
public void ThreadC(object data)
{
int num = (int) data;
int> int secondOneThird = 2 * oneThird;
for (int i=secondOneThird+1; i<=num; i++)
{
res = res * i;
}
Console.WriteLine("Final Out " + res);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote