You are on page 1of 7

Array 2

Array
• Array contain multiple elements, each element is of a
single type

arrayType array_name[array_size];

int letter_array[size]; Create an array that


for (j=1; j<=5; j++) contain 10 floating
{ point values as input
userPrompt();

cin>>letter_array[j];
}

6/10/2020 hfmh2019 2
Example 2
• Create an array that contains 10 positive numbers

int the_array [10];


Modify the code so that
int num;
the next input should be
bigger than the previous
for (int i=1; i<=10; i++){
one.
userPrompt();
num = getNumber();
if (num > 0)
{
the_array[i] = num;
} if (the_array[i-1] < num)
else the_array[i] = num;
i=i-1; else
} i=i-1;
6/10/2020 hfmh2019 3
Compare 2
elements
and Swap

6/10/2020 hfmh2019 4
Sort the
elements of
Array
(ascending)

6/10/2020 hfmh2019 5
Exercise 1
• Write a loop statement that calculate summation of two array
elements and store the summation values into a new array.
• Write statement that check if an array element is a positive or
negative.

6/10/2020 hfmh2019 6
Problem 1
• Assume an array containing a list of random alphabets.
• Write a function that check if the array element is a vowel.
• Count the number of vowels found on an array

6/10/2020 hfmh2019 7

You might also like