Sei sulla pagina 1di 1

1.

Write center (char ch, int count, int length) which prints count number of
characters in the center of a line of length characters. Make the other characters
of the line blank (or dot, for debugging purposes.) Here is the output for center
('*', 5, 13)
.... *****....

2. Write a function that swaps the first half of an array with the last half. Within
each half of the array, keep the elements in their original order. If the array has
an odd number of characters, the middle element remains where it is. Here is a
sample run:
Original:
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18

Swap Halves:

10 11 12 13 14 15 16 17 18 9
0 1 2 3 4 5 6 7 8

Note the requirement to keep the middle element in place for arrays with odd
numbers of elements. That requirement makes the puzzle harder than first
appears.

Write function that checks that the elements of an array are in ascending order.
Return 0 if the array is in order; otherwise, return the number of elements that
are out of order. Here are some sample runs:
1 2 3 4 6 7 8 7 10 11
13 20 31 41 41 45 50 53 52 52

2 elements out of order.

1 1 1 4 6 7 8 8 10 11
13 20 31 41 41 45 50 51 52 52

All elements are in order.

Potrebbero piacerti anche