The Lebanese University

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

The Lebanese University

Faculty of Economics and Business Administration (first Branch)


Subject: Introduction to Algorithm Year: 2009-2010
Duration: 60 Min. Instructor: Ali Saleh

Question #1 (7pts)
a) Write a pseudo code to input a pair of integers and determine if they are equal, have opposite signs
(one negative and the other positive), or the same sign. Print out a message, either “Equal”,
“Opposite Signs”, or “Same Sign”, for the appropriate case.
b) Draw a flow chart for the above pseudo code.

Question #2 (7 pts)
a) Write a pseudo code that adds all odd numbers between 0 and 50.
b) Draw a flow chart for the above pseudo code.

Question #3 (5 pts)
a) What is the difference between pretest loop (while), the post test loop (do while), and the FOR
loop?
b) What does the BREAK statement do?

Question #4 (4 pts)
Evaluate the following expressions. Also mark which expression is Boolean and which is
mathematical:
a) (x-2)/2*y-3 < (y*x-3)/2*2 where x=5 and y=-3
b) w=(2*z-25)/2+3*z where z=8

Question #5 (7 pts)
a) Determine the output of the following program assuming that the user enters 5 for the value N.
main program
Declare A , i, N, term as Integer
Declare acc as Real
Begin
Write "Enter an integer"
Input (N)
A=4
i=1
acc = 0
do
Term = A + i
acc = acc + term / (N- i + 1)
Write "Term (", i ,")=", Term
i=i+1
while (i <= N)
Write "The result is : ", acc
Write "Number of iterations: ", i - 1
Write "--------------- THE END ----------------"
End

b) Draw the flow chart of the above pseudo code.

Good Luck

You might also like