Week 2 Lab Ex 1
In this lab we learn about Sorting an array, using ForEach loop, and Random class:
- Open Visual Studio 2012
- Create a new project by going to File --> New --> Project
- Select Visual C# --> Windows Desktop --> Console Application
- In the Name field, type "W2Lab1-[Last_name]", where [Last_Name] is replaced with your last name.
- In the location field, give a directory location and click ok.
- Add code to declare and initialize an Int array that can hold 7 Integers.
- Using a For loop assign random numbers from the range 1 to 49 inclusive to the above array.
- Sort the array
- Using a ForEach loop display the seven numbers separated by tabs to console
Week 2 Lab Ex 2
In this lab we learn about Linear Search and break:
- Add new console application project to the above solution
- Create an array which hold 20 random numbers in the range of 1 and 100.
- Using a For loop search for an integer given by user.
- Break out of the loop if the integer is found.
Week 2 Lab Ex 3
In this lab we learn about BinarySearch() :
- Add new console application project to the above solution
- Copy the code from Ex2
- Sort the array using Array.Sort()
- Edit to perform a binary search using Array.BinarySearch() rather than a Linear search.
Comments
Post a Comment