Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Problem#1
- Write a C program that populates a 10 x 10 square 2d array of integers. Use a nested
- for loop to fill the array with the value of the row times the column. Compose a
- function that receives the array as a parameter and prints the contents to screen
- using nested for loops. Your output should resemble the output shown below. Itโs
- the 10 times table. Hint: Test the main function before adding another to minimize
- time spent troubleshooting.
- Problem#2
- Write a program that declares a single dimensional array of 10 integers. Create a
- function that uses a for loop to load the array with random integers from 0 to 20.
- Add a second function using a for loop to print the contents to the screen separated
- by spaces or commas. Your functions will need to take the array and the size as
- parameters as a minimum. You may add more parameters as you wish. Run your
- program a few times. Are the numbers random?
- //View my solution, yours may be different, thatโs okay.
- Problem #3
- Using the previous program or my solution, Add a prompt to the user to enter in one
- of the displayed values. Declare a new local declared variable to store the entered
- value. This will be a search term. Create a linear/sequential search function to
- search the array for the entered value. Your function will return the index indicating
- the location of the element and the program will display the location(index) to the
- user.
- Your function will need to return an integer, take an integer array, a size variable,
- and a search term variable as parameters. Make sure to declare a variable in the
- calling function (main) to store the returned value. NOTE: your solution may not
- deal with duplicates and I am not asking you to check.
- Problem #4
- Create a program that declares an array of 10 integers. Initialize the array with
- numbers in ascending order. They can be 0 โ 9 or randomly picked by you. Create a
- new function called binarySearch. This function will take the same parameters but
- instead of visiting each element in the array it will use the binary search method.
- You may look at the example in the Zybook 11.4.1 for guidance. What this function
- does is find a new middle to the array after each search, halving the size of the array
- to search with each failed search. This search method relies on the array being
- searched being in order. If it is not in order the element being searched will be
- missed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement