0% found this document useful (0 votes)
20 views

Array Exercises

The document provides pseudocode and descriptions for 6 exercises involving arrays. Exercise 1 involves creating an array of names and counting how many times each name appears. Exercise 2 involves creating an array of names and counting the number of letters in each name. Exercise 3 creates an array of names and counts the vowels in each name. Exercise 4 creates an array of 20 random numbers and counts the even and odd numbers. Exercise 5 creates arrays for suits and ranks to randomly generate and display a card. Exercise 6 generates 8 unique random numbers as a lottery number set.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Array Exercises

The document provides pseudocode and descriptions for 6 exercises involving arrays. Exercise 1 involves creating an array of names and counting how many times each name appears. Exercise 2 involves creating an array of names and counting the number of letters in each name. Exercise 3 creates an array of names and counts the vowels in each name. Exercise 4 creates an array of 20 random numbers and counts the even and odd numbers. Exercise 5 creates arrays for suits and ranks to randomly generate and display a card. Exercise 6 generates 8 unique random numbers as a lottery number set.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Array Exercise 1

Create an array with the following names Francis, Anthony, Paul, Peter, Francis, John, Luke, Francis,
Paul, Francis. Your program is then to count the number of times each name appears in the array.

Pseudocode

ARRAY SAINTS = FRANCIS, ANTHONY, PAUL, PETER, JOHN, LUKE, FRANCIS, FRANCIS, PAUL, FRANCIS

STRING FOR EACH NAME IN ARRAY

INT FOR EACH NAME IN ARRAY = 0

FOREACH (NAMES IN ARRAY SAINTS)

IF (NAMES = NAME OF SAINT)

NAME COUNTER++

PRINT NAME APPEARED _ TIMES

Array Exercise 2

Create an array with the following names John, Paul, Ringo, George, Keith, Mick, David, Elvis,
Richard, Frank. Your program is to count how many letters they have in their names. The display
should be: John Has 4 Letters.

Array Exercise 3

Create an array with the following names John, Paul, Ringo, George, Keith, Mick, David, Elvis,
Richard, Frank. Your program is to count the number of vowels they have in their name. For
example, John has 1 vowel in its name.

Array Names = John, Paul, Ringo, George, Keith, Mick, David, Elvis, Richard, Frank

Array Vowels = a,e,i,o,u

Int counter = 0

Foreach (string in vowels)

Foreach (string in names)


{

If (name contains letters)

Counter ++

Print name + counter

Int Counter = 0

Array Exercise 4

Create an array with 20 numbers. Then inside program is to count the number of even and odd
numbers in the array. The display should be.
Number of Even numbers =
Number of Off numbers =

Array numbers (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

start
print "enter the number - "
read number
if number mod 2 = 0 then

display "number is even"

else

display "number is odd"

Else if (array numbers = odd)

Int odd Counter ++

Else (array numbers = int)

Int even counter ++

end if
Array Exercise 5

Create 2 arrays.

suit = { "Clubs", "Diamonds", "Hearts", "Spades" };

rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"}

Your program is to generate a random card and display the result. For example Ace of Diamonds

Array Exercise 6 (Advance)

Lotto number generator. Create a program that will store 8 random numbers into an array. Once 8
numbers have been reached the output should display Your winning numbers are: .

Please note that once a number has been generated it cannot be used again.

You might also like