Pseudocode
Part A: Construct task for the following pseudocode.
pseudocode Task
1 A = 5
B = 10 this pseudocode’s output related to “A” being greater
or less than “B”.
if A < B then
output A, " is less than ", B
else
output A, " is greater than ", B
end if
2 STR1 = "red" output = “blue”
STR2 = "blue"
if NOT STR1 = STR2 then
STR1 = "blue"
end if
output STR1
3 COUNT = 0 count increases until reaches its limit “<20”
loop while COUNT < 20
output COUNT
COUNT = COUNT + 2
end loop
4 COUNT = 0 SUM=45
SUM = 0
loop until COUNT = 10
SUM = SUM + COUNT
COUNT = COUNT + 1
end loop
5 loop X from 1 to 10
if X mod 2 = 0 then
output "even" arrange even and odd numbers
else
output "odd"
end if
end loop
6 loop X from 0 to ARRAY.length - 1 array.length - 1
if ARRAY[X] > ARRAY[X + 1] then
TEMP = ARRAY[X + 1]
ARRAY[X + 1] = ARRAY[X]
ARRAY[X] = TEMP
end if
end loop
Part B: Convert the following flowcharts into pseudocode.
flowchart pseudocode
7 A = 5
B = 10
if A < B then
output A, " is less than ", B
else
output A, " is greater than
", B
end if
A=1
loop A from 1 to 10
if A mod 2 = 0 then
output "A"
else
A=A+1
9
X=0
while loop
SUM=SUM+ARRAY[X]
X=X+1
IF X>ARRAY.length[x] end loop
output AVG=SUM div ARRAY.length
Part C: Write pseudocode for the following problems.
10. Determine if two numbers are equal. If they are equal print "same" otherwise print "different".
A=int
B=int
if B=A printout (“same”)
else printout (“different”)
11. A method returns true if a given string contains the letter "a" otherwise it returns false.
A=str
divide A to char “B”
if B=”a”, true
else false
12. A method returns true if a given number is prime otherwise it returns false. A number is prime if it
is only divisible by itself and one.
i = int
if (i/i=1) true
else false