0% found this document useful (0 votes)
7 views2 pages

Labsheet10 Functions

Uploaded by

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

Labsheet10 Functions

Uploaded by

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

Problem Solving and Algorithmic Thinking

B. Tech (ECE and CCE) – I Semester


Expt – 10
Functions [CO1, CO2, CO3, CO4]
Objective:
This week will involve understanding the use of functions in flowgorithm.

Pre-lab Questions (Answer these questions before coming to the lab).


1. List five advantages of using functions in a program.
2. What are formal and actual parameters in a function?
3. Read the code given and answer the following questions.

Module integer factorial(Integer value) is


Start Start
Step1:Declare i=1, fact=1 Step1: Declare n, r, f1,f2,f3, result
Step2: Step2: Print “Enter the n and r value “
Step 2.1 Repeat the following steps Step3: Read n, r
until i<=value Step4: f1= factorial (n)
Step: 2.2 fact =fact *i Step5: f2= factorial (r)
Step: 2.3 i=i+1 Step6: result=f1/(f2*3)
Step3: return fact Step7: Display the value of result
EndModule End

a. Name the formal and the actual arguments in the given program.
b. How many times is the factorial function being executed?
c. Assuming n=2, r = 3 what is the output of step 6.
d. If step 6 is modified as result = i* f1/(f2*3), what will be the value of result ?

4. Do the following in flowgorithm.


a. Create a factorial function as given in question 3 and draw the corresponding snapshot of the
same. (Please note: It is enough to just show the top level function declaration. No need to
write the full contents of the function)
b. How do we use this function inside the main program? Draw the corresponding snapshot
showing this function being called.

5. ‘Qualcomm Snapdragon’, ‘Intel core i9’, ‘AMD Ryzen’- I am sure you have heard these terms. These
are some of the trending microprocessors used in our mobile phones and computers.

One of the most commonly used blocks in a microprocessor is an ‘ALU: Arithmetic and Logic’ unit which
consists of two blocks that perform most the common arithmetic and logical operations like addition,
subtraction, AND, OR etc.

Given below in Fig. 1 is a block diagram of an ALU that consists of the arithmetic unit, logic unit and a
multiplexer (MUX) and controlled by 2 signals ‘select: sel’ and ‘choice’. The inputs to the system are A,
B, Cin, ‘sel’ and ‘choice, while the output is ‘y’.

A and B are inputs going into the logic unit, while A, B and Cin go as inputs to the arithmetic unit.
Table 1 details the operations performed by each of the 2 units controlled by the ‘sel’ and ‘choice’
signals. The function of the multiplexer is to choose the output coming from either the arithmetic or
the logic unit as can be seen in the table.
• Write an algorithm describing the working of the ALU.
• Please note that each operation should be written as a function (totally 8 functions for 8
operations). These functions should be called in the main program wherever needed, based
on the values of the ‘sel’ and ‘choice’.

Fig. 1 Block Diagram of an Arithmetic and Logic Unit

Choice Sel Operation Function Unit being activated

0 A + B + Cin ADD

1 A - B - Cin SUB
0 Arithmetic Unit
2 Increment A INCA

3 Multiply A and B MUL

0 A AND B AND

1 A OR B OR
1 Logic Unit
2 NOT A INVA

3 NOT B INVB

Table 1: Operation table of the ALU unit

Procedure:

Using flowgorithm implement the questions being given in class during the lab sessions.

You might also like