Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Course Code CS201

Description Computer Programming 1

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

Description Computer Programming 1

Laboratory
Title of
Exercise 008 Divide Them All
Activity
No.
Page 2 of 6
LABORATORY EXERCISE
FLOWCHART PSEUDOCODE

Function Definition: Function Definition:


Divide( x,y)
divide (x,y)
RETURN x/y
RETURN x/y
Main Flowcharts:
Main flowchart:
DECLARE n[6]
START DECLARE i
FOR (i=0; i<6; i = i + 1)
INPUT n[i]
DECLARE LOOP
n [6] CALL divide (n[0], n[1])
CALL divide (n[2], n[3])
CALL divide (n[4], n[5])
DECLARE OUTPUT “The quotients are: “+divide (n[0], n[1]
i + “,”“+divide (n[2], n[3] + “and” “+divide (n[4],
n[5] + “.”
END
i=0

False True
i<6

divide (n[0], ACCEPT


n[1] n [i]

divide (n[2], i=i+1


n[3]

divide (n[4],
n[5]

DISPLAY “The quotients are:


“+divide n[0] + n[1] +”,” +
divide n[2] +n[3] + ”and “ +
divide n[4] +” and “ +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

Description Computer Programming 1

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

Description Computer Programming 1

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

Description Computer Programming 1

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

f[i] = f[i-1] + f[i-2]

i=i+1
RETURN f(x)

Main Flowchart:
START

DECLARE
n

INPUT
n

fibonacci (n)

DISPLAY “The “+n + “th term


in the Fibonacci sequence is”
+ Fibonacci (n) + “ . “

4. What can you conclude from this activity?


END

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.

You might also like