A linear array can be used to store a simple list of data.
Assume that the array ages[] contains 10
int values.
Write a loop that counts ages
that are between 15 and 20.
int[] ages = {17 , 25, 13 , 18 , 19 , 12 , 28 , 65 , 17 , 18};
int count = 0;
for(int c = 0; c < 10 ; c = c +
1)
{
if ( ages[c] >=
15 && ages[c] <= 20
)
{
count =
count + 1;
}
}
output("Found " + count + " ages between 15 and 20");
//** The correct result for the array above is 5 **