
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document demonstrates the use of parallel arrays to store and retrieve data using an example of an array of item numbers and their corresponding prices. The document also includes a function to search for the index of a target item number and then uses that index to retrieve the price. This is a useful technique for organizing and accessing data in a program.
Typology: Study notes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Parallel arrays int itemNumber[10] [0] 1234 [1] 6529 [2] 9983 [3] 4567 [4] 2020 [5] 9987 [6] 1212 [7] 3948 [8] 0098 [9] 8876 double price[10] [0] 386. [1] 0. [2] 12. [3] 99. [4] 99. [5] 23. [6] 0. [7] 386. [8] 8. [9] 0. Suppose we want to find the price of item 2020. Given the function: int search( int theArray[ ], int arrSize, int target ) /* search theArray (of size arrSize) for the first occurrence of target. Return the index if it is there. Return - 1 if it does not occur in theArray */ We can use it: int location; location = search(itemNumber, 10, 2020); if (location != - 1) printf ("It costs $%0.2lf.\n", price[location]); else printf("We do not have that item..\n");