Answer the following about the declaration int amount[25];
a) How many elements are in the array?
b) What are the upper and lower bounds of the array?
(Hint upper bound = 24, lower bound = 0 why?)
Answers
If the array has 5 elements, we can use int(random(5)) to choose the element and we will get back the integer numbers 0, 1, 2, 3 and 4, never 5, which is exactly what we want. In an array that has 5 elements, the first element is 0 and the last one is 4.
Upper - Lower Bounds. The lowest and highest index numbers are known as bounds. Arrays have both upper and lower bounds, and the elements of the array are contiguous within those bounds.
"a) There are 26 elements in the given array amount[25], that is ranging from 0 to 25. Hence, the total data elements in the given array can be 26.
b) The upper bound value is 24 as the upper bound returns either the starting element in the row of the array which is greater value or returns last element if none of the element is found.
The lower bound is 0 because Lower bound returns the first element, which is not lesser than the given element value. The lower bounds and upper bounds uses element in a classified order.
"