L5 - CD 303 Array and Its Operations With Memory Representation
L5 - CD 303 Array and Its Operations With Memory Representation
Example:
An automobile company uses an array AUTO to record the number of
automobiles sold each year from 1932 through 1984.
1. AUTO[K] =number of automobiles sold in the year K
2. LB = 1932 UB = 1984
3. Length = UB – LB + 1 = 1984 -1930 + 1= 55
4. That is, AUTO contains 55 elements.
Example:
Find the number NUM of years during which more than 300 automobiles were
sold.
1. [Initialization] Set NUM:= 0
2. Repeat for K = 1932 to 1984:
If AUTO[K] > 300, then:
Set NUM := NUM+ 1
[End of loop.]
3. Return.
Example:
Print each year and the number of automobiles sold in that year.
1. Repeat for K = 1932 to 1984:
Write: K, AUTO[K]
[End of loop.]
2. Return