Algorithm - ICT4U.NET

advertisement
Writing Algorithms
Challenge 1
Write an algorithm that displays all numbers from 1 to 50 that are exactly divisible by 5
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
AJK Jan 2015
Page 1 of 9
Writing Algorithms
Challenge 2
Write an algorithm that displays the numbers from one to ten omitting numbers five and
seven
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
Set value of counter to 1
Do
If value of counter is not equal to 5 OR value of counter is
not equal to 7
Display value of counter
End if
Add 1 to value of counter
While value of counter is less than 11
AJK Jan 2015
Page 2 of 9
Writing Algorithms
Challenge 3
The following words are held in a data store:
coffee
orange
pasta
cheese oats
margarine
tomato
apple
chocolate
Write an algorithm that creates a new data store with the words in reverse order
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
AJK Jan 2015
Page 3 of 9
Writing Algorithms
Challenge 4
Write an algorithm to display the following data
WHITE
BLACK
WHITE
BLACK
BLACK
WHITE
BLACK
WHITE
WHITE
BLACK
WHITE
BLACK
BLACK
WHITE
BLACK
WHITE
WHITE
BLACK
WHITE
BLACK
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
AJK Jan 2015
Page 4 of 9
Writing Algorithms
Challenge 5
Write an algorithm to display this graphic
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
AJK Jan 2015
Page 5 of 9
Writing Algorithms
Challenge 6
Write an algorithm work out a happiness rating:
1=unhappy; 2-4 =sad; 5-7 = ok; 8-9=happy; 10= very happy
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
Get HappinessScore
If HappinessScore = 1 then
Set HappinessRating to “ Unhappy”
Else
If HappinessScore GT equal 2 and HappinessScore LT equal 4 then
Set HappinessRating to “ Sad”
Else
If HappinessScore GT equal 7 and HappinessScore LT equal 7 then
Set HappinessRating to “ Ok”
Else
If HappinessScore GT equal 8 and HappinessScore LT equal 9
then
Set HappinessRating to “ Happy”
Else
If
HappinessScore equal 10
Set HappinessRating to “ Very Happy”
End if
End if
End if
End if
AJK Jan 2015
Page 6 of 9
Writing Algorithms
Challenge 7
Write an algorithm display the vowels (a,e,I,o,u) in a phrase entered by the user:
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
Accept Phrase entered by the user
vowels = “a”, “e”, “I” ,”o” ,”u”
Set index to 1
Repeat
If letter of phrase at position index is in vowels then
Add letter of phrase at position index to result
End if
Add 1 to index
Until index greater than number of letters in phrase
AJK Jan 2015
Page 7 of 9
Writing Algorithms
Challenge 8
Write an algorithm to count the number of words in a phrase entered by the user:
Write your solution in the section below the line.
Detach the challenge and pass your solution to your code buddy.
DO NOT tell your code buddy what the algorithm is for
Algorithm
AJK Jan 2015
Page 8 of 9
Writing Algorithms
Algorithm
AJK Jan 2015
Page 9 of 9
Download