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

C# with Visual Studio Part 1: Exploration of asynchronous programming a) Using t

ID: 3706322 • Letter: C

Question

C# with Visual Studio

Part 1: Exploration of asynchronous programming a) Using the Fibonacci code from the slide deck you will loop from 0 to 35 and fill two different arrays Array 1 will have the Fibonacci value for the index that it is sitting in (array index 10 will have the result for Fibonacci 10 Array 2 will have how long it took to for the program to get the answer for the Fibonacci value in that index (therefore: these are parallel arrays) Use the stopwatch class to do the timing. It will start at the beginning of the code The time for the calculation will be how long it took for the Fibonacci value to be calculated since the program first started to run- fib 3 will be longer than fib 1 will be longer than fib 0 a. b. c. d. e, Note: this is not done asynchronously f. Print out the values and the time that had elapsed up to that point to calculate the value i. Fib(1)-1 in 0ms ii. Fib(2) 1 in O ms iii. Fib(3) 2 in 0.0000003 ms b) You will do the Fibonacci calculation again. But this time you will use the parallel processing a. In this part you will use the parallel.for command to run the Fibonacci code b. You will save the values using new parallel arrays c. Print out the values and the time that had elapsed up to that point to calculate the value

Explanation / Answer

using System;  

public class FibonacciExample  

{  

public static void Main(string[] args)  

{  

var watch = new System.Diagnostics.Stopwatch();

int n1=0,n2=1,n3,i,number;   

Console.Write("Enter the number of elements: ");   

number = int.Parse(Console.ReadLine());  

Console.Write(n1+" "+n2+" ");

watch.Start();

for(i=2;i<number;++i)

{  

  

n3=n1+n2;   

Console.Write(n3+" ");

n1=n2;   

n2=n3;   

watch.Stop();

Console.WriteLine("Execution Time: "+watch.ElapsedMilliseconds+" ");

}   

}  

}