Professional Documents
Culture Documents
Laboratory Exercise: Questions
Laboratory Exercise: Questions
Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 1 of 6
LABORATORY EXERCISE
Questions:
1. Write a program that can divide six non-zero integers (two integers per division) from the user
and display the result to the user. Create a function that will perform the division operation.
Display only the non-decimal part of the quotient.
1
Course Code CS201
Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 2 of 6
LABORATORY EXERCISE
FLOWCHART PSEUDOCODE
False True
i<6
divide (n[4],
n[5]
END
2. Write a program that will accept a short value from 10 to 99 and display them per digit (separated
by a space).
2
Course Code CS201
Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 3 of 6
LABORATORY EXERCISE
FLOWCHART PSEUDOCODE
Function Definition:
Function Definition: Divide( x,y)
digit (value)
DECLARE x, y
DECLARE SET x TO value / 10
x/y SET y TO value % 10
IF value > 9 && value < 100 THEN
OUTPUT x + “ “ + y
3
ELSE
CALL DoEndline()
END
Course Code CS201
xDescription
= value / 10 Computer Programming 1
Laboratory
Title of
Exercise 008 y = value % 10 Divide Them All
Activity
No.
Page 4 of 6
LABORATORY EXERCISE
False True
value > 9 &&
value < 100
Endline
DISPAY x+” “ +y
RETURN
Main Flowchart:
START
DECLARE
n
ACCEPT
n
digit n
END
3. Write a program that will display the nth Fibonacci number. Create a function that will generate
the nth Fibonacci number. Fibonacci numbers are numbers from the Fibonacci sequence which
follows the pattern of 1, 1, 2, 3, 5, 8, 13, 21, 33, 54…
4
Course Code CS201
Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 5 of 6
LABORATORY EXERCISE
FLOWCHART
Function Definition: fibonacci
DECLARE
f[x+2]
5
Course Code CS201
Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 6 of 6
LABORATORY EXERCISE
f[0] = 0
f[1] = 1
DECLARE
i
i=2
False True
i<=x
i=i+1
RETURN f(x)
Main Flowchart:
START
DECLARE
n
INPUT
n
fibonacci (n)
My conclusion from this activity is that functions are very helpful in making codes more orderly.
Using functions, you can make your code more precise, clear and can be easily comprehend.