You are on page 1of 6

Introduction to problem solving

Assignment

What is the output of the following pseudocode?

start
declare intager i, j, m.
i=3 ,
j=2.
m=++i + j++
print m.
End.

The output is
6

What is the output of the following pseudocode segment


X=10
Y=20
Print “X+Y”

The output is

1020

Suppose price is 6001, what is the output of the following pseudocode segment
If (price== 6000) then
Print “price is equal to 6000”
else If (price< 6000) then
Print “price is less than 6000”
else print price

The output is

6001
Introduction to problem solving

Write a pseudocode that corresponds to the following flowchart

start
declare a
declare b

input a
input b
result = a * b
if result == 1 then
print " b is the invers of a "
else
print " b is not the invers of a "
end if

End
Introduction to problem solving

Draw the flowchart corresponding to the following pseudocode:


Step 1: Start
Step 2: Declare M1, M2, M3 and Grade
Step 3: Input M1
Step 4: Input M2
Step 5: Input M3
Step 6: Calculate the average grade with formula "Grade=(M1+M2+M3)/3"
Step 7: If the average grade is greater than 60, print "Pass", else print "Fail".
Step 8: End

start

Declare M1, M2, M3 and Grade

Input M1 , M2 , M3

average grade
= (M1+ M2+M3)/ 3

if
yes no
average grade
>=60

Print "Pass" Print " Fail "

stop
Introduction to problem solving

What is the output of the following program?

Start
Declare n
n=4
While (n >= 0)
Display (n*n)
--n
EndWhile
Display n
While (n < 4)
Display n++
EndWhile
Display n
End

The output is :
4 // first while
5 // second while
Introduction to problem solving

Rewrite the following pseudocode segment using a For loop.


i=0
While (i < 20)
if (i % 2 == 0)
Display “even”
else
Display “odd”
EndIF
i++
EndWhile

The Rewrite is:

For (1=0 ; i < 20; i++)


if (i % 2 == 0)
Display “even”
else
Display “odd”
EndIF
End

What is the purpose of the following flowchart?

The purpose of the flowchart is to calculate the


numbers that are divisible by 3 for the numbers
between zero and 15
Introduction to problem solving

What the suitable pseudo code that corresponds to the flowchart below

a)
Step 1: Read values a and b,

Step 2: compute the product b*b

Step 3: If the product is not equal to


1 then b is the inverse of a,

Step 4: Print output

You might also like