Previous: 7.9 Exercises
Up: 7 Arrays
Previous Page: 7.9 Exercises
- Write a program that uses the sizeof operator to print the size of an array
declared in the program. Use the sizeof operator on the name of the array.
- Write a function that prints, using dereferenced pointers, the elements of
an array of type float.
- Write a function that checks if a given integer item is in a list.
Traverse the array and check each element of the list. If an element is found
return True; if the array is exhausted, return False.
- Write a function that takes an array of integers and returns the index
where the maximum value is found.
- Write a function that takes an array and finds the index of the maximum
and of the minimum.
Use arrays to house sets of integers. A set is a list of items. Each item of a
list is a member of a list and appears once and only once in a list. Write the
following set functions.
- Test if a number is a member of a set: is the number present in the set?
- Union of two sets A and B: the union is a set that contains members of each
of the two sets A and B.
- Intersection of two sets A and B: the intersection contains only those
members that are members of both the sets A and B.
- Difference of two sets A and B: The new set contains elements that are
members of A that are not also members of B.
- Write a function to read a string from the standard input. Read characters
until a newline is reached, discard the newline, and append a NULL. Use array
indexing.
- Write a function to read a string from the standard input. Read characters
until a newline is reached, discard the newline, and append a NULL. Use
pointers.
- Write a function to write a string to the standard output. Write
characters until a NULL is reached, discard the NULL, and append a newline. Use
pointers.
- Write a function to change characters in a string: change upper case to
lower case and vice versa. Use array indexing.
- Write a function to change characters in a string: change upper case to
lower case and vice versa. Use pointers.
- Write a function that counts and returns the number of characters in a
string. Do not count the terminating NULL. Use array indexing.
- Write a function that counts and returns the number of characters in a
string. Do not count the terminating NULL. Use array indexing.
- Write a function that removes the last character in a string. Use array
indexing to reach the last element and replace it with a NULL.
- Write a function that removes the last character in a string. Use pointers
to traverse the array.
- Repeat problems 24 and 25, but use the function of problems 22 or 23.
Previous: 7.9 Exercises
Up: 7 Arrays
Previous Page: 7.9 Exercises