1. Given: int values[4][5] Write a nested loop to set values as follows: [0] [1] [2] [3] [4] [0] 1 2 3 4 5 [1] 1 2 3 4 5 [2] 1 2 3 4 5 [3] 1 2 3 4 5 2. Given: int values[4][5] Write a nested loop to set values as follows: [0] [1] [2] [3] [4] [0] 0 1 2 3 4 [1] 1 2 3 4 5 [2] 2 3 4 5 6 [3] 3 4 5 6 7 3. Given: int matrix[5][5] Write a nested loop to set matrix as follows: [0] [1] [2] [3] [4] [0] 1 0 0 0 0 [1] 0 1 0 0 0 [2] 0 0 1 0 0 [3] 0 0 0 1 0 [4] 0 0 0 0 1 4. A square matrix has the same number of rows and columns. The diagonal of a square matrix is made up of the entries which run from the upper left corner to the lower right corner. In the previous problem, the diagonal is made up of those entries which are equal to 1. A square matrix is upper triangular if all entries below the diagonal are 0. The diagonal entries and the entries above the diagonal can have any value, including 0, but all entries below the diagonal must have the value 0. Write a function called isUpper which has two parms: an array with N rows and N columns, and the size of the array. The function should return true if the array represents an upper triangular matrix, and return false otherwise. Given the following array of 5 rows and 5 columns, which contains the distances between cities:
[0] | [1] | [2] | [3] | [4] | ||
---|---|---|---|---|---|---|
Albany | Boston | Hartford | NY | Phila | ||
[0] | Albany | 0 | 171 | 115 | 141 | 240 |
[1] | Boston | 171 | 0 | 103 | 194 | 333 |
[2] | Hartford | 115 | 103 | 0 | 120 | 235 |
[3] | NY | 141 | 194 | 120 | 0 | 104 |
[4] | Phila | 240 | 333 | 235 | 104 | 0 |
Note that the city names are not in the array; the array contains the numeric entries only, which give the distance between the two cities represented by the row and column. 5. Write the statements to initialize an array distance with the mileage data given above. 6. Write a function which will print the following menu, read in two city numbers, and return the two city numbers entered: To determine the mileage between cities, enter the numbers of two cities from the following list: 1: Albany 4: NY 2: Boston 5: Phila 3: Hartford Enter your city numbers: 7. Write the statements to call your menu function and then print the distance between the two cities requested.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2004