33. Write a function named "rotate_right" that takes as its arguments the following:
(1) an array of floating point values;
(2) an integer that tells the number of cells in the array;
The function should shift the contents of each cell one place to the right, except for the contents of the
last cell, which should be moved into the cell with subscript 0 . Thus, for example, if the array passed
to the function looks like this:
0 1 2 3 4
5.8 | 2.6 | 9.1 | 3.4 | 7.0
then when the function returns, the array will have been changed so that it looks like this:
0 1 2 3 4
7.0 | 5.8 | 2.6 | 9.1 | 3.4
The function should not return a value.
34. Write a function named "shift_right" that takes as its arguments the following:
(1) an array of floating point values;
(2) an integer, call it "left", that tells the leftmost cell of the part of the array to be shifted;
(3) an integer, call it "right", that tells the rightmost cell of the part of the array to be shifted;
(4) a positive integer, call it "distance" that tells how many cells to shift by.
The function should make sure that left is less than or equal to right, and that distance is greater than
zero. If either of these conditions fails, the function should return the value 1 to indicate an error.
Otherwise it should shift by distance cells the contents of the array cells with subscripts running from
left to right . Thus, for example, if the array passed to the function looks like this:
0 1 2 3 4 5 6 7 8 9 10 ....
5.8 | 2.6 | 9.1 | 3.4 | 7.0 | 5.1 | 8.8 | 0.3 | -4.1 | 8.0 | 2.7 | etc.
and if left has the value 3 , right has the value 7 , and distance has the value 2 , then the function
should shift the contents of cells 3 , 4 , 5 , 6 , and 7 to the right by 2 cells, so that when the function
returns, the array will have been changed so that it looks like this:
0 1 2 3 4 5 6 7 8 9 10 ....
5.8 | 2.6 | 9.1 | ??? | ??? | 3.4 | 7.0 | 5.1 | 8.8 | 0.3 | 2.7 | etc.
The question marks in cells 3 and 4 indicate that we don't care what numbers are in those cells when
the function returns. Note that the contents of cells 8 and 9 have changed, but the contents of cell 10
is unchanged. The function need not take any precautions against the possibility that the cells will be
shifted beyond the end of the array (the calling function should be careful not to let that happen).
35. Write a function named "subtotal" takes as its arguments the following:
(1) an array of floating point values;
(2) an integer that tells the number of cells in the array.
The function should replace the contents of each cell with the sum of the contents of all the cells in the
original array from the left end to the cell in question. Thus, for example, if the array passed to the
function looks like this:
0 1 2 3 4
5.8 | 2.6 | 9.1 | 3.4 | 7.0
then when the function returns, the array will have been changed so that it looks like this:
0 1 2 3 4
5.8 | 8.4 | 17.5 | 20.9 | 27.9