0% found this document useful (0 votes)
31 views6 pages

Pseudocode

The pseudocode outputs whether A is less than or greater than B, outputs the changed string STR1 as 'blue', counts by 2s until reaching 20, calculates a running SUM as it loops from 0 to 10, and arranges even and odd numbers from an array.

Uploaded by

alihansalim8371
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views6 pages

Pseudocode

The pseudocode outputs whether A is less than or greater than B, outputs the changed string STR1 as 'blue', counts by 2s until reaching 20, calculates a running SUM as it loops from 0 to 10, and arranges even and odd numbers from an array.

Uploaded by

alihansalim8371
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

You might also like