Solved Assignment Problems - Algorithms and Flowcharts
Algorithm
An algorithm is defined as sequence of steps to solve a problem (task). The steps must be finite, well defined
and unambiguous. Writing algorithm requires some thinking. Algorithm can also be defined as a plan to solve a
problem and represents its logic. Note that an algorithm is of no use if it does not help us arrive at the desired
solution
Algorithm characteristics
1. It should have finite number of steps. No one can be expected to execute infinite number of steps.
2. The steps must be in order and simple
3. Each step should be defined clearly i.e. without un-ambiguity (without doubtfulness)
4. Must include all required information
5. Should exhibit at least one output
Flowchart
A flowchart is a pictorial (graphical) representation of an algorithm. A flowchart is drawn using different
kinds of symbols. A symbol is used for a specific purpose. Each symbol has name.
Algorithm Flowchart Program
An algorithm is defined as A flowchart is pictorial Set of instructions. Instruction is
sequence of steps to solve a (graphical) representation of a command to the computer to
problem (task). an algorithm. do some task.
Algorithm can also be defined as A picture is worth of 1000 Implementation of Algorithm or
a plan to solve a problem and words. We can understand more flowchart
represents its logic. from picture than words.
Different algorithms have different performance characteristics to solve the same problem. Some
algorithms are fast. Some are slow. Some occupy more memory space. Some occupy less memory
space. Some are complex and some algorithms are simple.
Logically algorithm, flowchart and program are the same.
1|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q1. Create a program to compute the volume of a sphere. Use the formula: V = (4/3) *pi*r3 where pi is
equal to 3.1416 approximately. The r is the radius of sphere. Display the result.
Algorithm Flowchart
1. Start Start
2. Read r
3. vol = (4/3) *pi*r*r*r
4. Print or display vol
5. Stop Read r
vol = (4/3) *pi*r*r*r
Write vol
Stop
Q2. Write a program the converts the input Celsius degree into its equivalent Fahrenheit degree. Use
the formula: F = (9/5) *C+32.
Algorithm Flowchart
1. Start Start
2. Initialize F=0, C=0
3. Read C
4. Fh = (1.8*C) + 32
C=0, F=0
5. Print or display Fh
6. Stop
Read C
Fh = (1.8*C) + 32
Write Fh
Stop
2|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q3. Write a program that converts the input dollar to its peso exchange rate equivalent. Assume that
the present exchange rate is 51.50 pesos against the dollar. Then display the peso equivalent exchange
rate.
Algorithm Flowchart
1. Start
2. Read dollar Start
3. peso = dollar * 51.50
4. Print or display peso
5. Stop Read dollar
peso = dollar * 51.50
Write peso
Stop
Q4. Write a program that converts an input inch(es) into its equivalent centimeters. Take note that one
inch is equivalent to 2.54cms
Algorithm Flowchart
1. Start Start
2. Read inch
3. cm = 2.54 * inch
4. Print or display cm
Read inch
5. Stop
pcm = 2.54 * inch
Write cm
Stop
3|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q5. Write a program that exchanges the value of two variables: x and y. The output must be: the value
of variable y will become the value of variable x, and vice versa.
Algorithm Flowchart
1. Start
2. Read x, y Start
3. Declare third variable, z
z=x
x=y Read x, y
y=z
4. Print or display x, y
5. Stop z=x
x=y
y=z
Write x, y
Stop
Q6. Design a program to find the circumference of a circle. Use the formula: C=2πr, where π is
approximately equivalent 3.1416.
Algorithm Flowchart
1. Start
2. Read r Start
3. Calculate circumference by
the equation:
Circum = 2*pi*r Read r
4. Print Circum
5. Stop
Circum = 2*pi*r
Write
Circum
Stop
4|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q7. Write a program that takes as input the purchase price of an item (P), its expected number of years
of service (Y) and its expected salvage value (S). Then outputs the yearly depreciation for the item (D).
Use the formula: D = (P - S) Y.
Algorithm Flowchart
1. Start
2. Read P Start
3. Read S
4. Read Y
5. D = (P-S) * Y Read P
6. Print or display D
7. Stop
Read S
Read Y
D = (P-S) * Y
Write D
Stop
5|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q8. Swapping of 2 variables without using temporary (or 3rd variable)
Algorithm Flowchart
1. Start
2. Read x and y Start
3. x = x + y
y=x-y
x=x-y Read x, y
4. Print or display x, y
5. Stop
x=x+y
y=x-y
x=x-y
Write x, y
Stop
6|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q9. Determine the most economical quantity to be stocked for each product that a manufacturing
company has in its inventory: This quantity, called economic order quantity (EOQ) is calculated as
follows: EOQ=2rs/1 where: R= total yearly production requirement S=set up cost per order
I=inventory carrying cost per unit.
Algorithm Flowchart
1. Start
2. Read R Start
3. Read S
4. Read I
5. EOQ = (2*R*S)/I Read R
6. Print EOQ
7. Stop
Read S
Read I
EOQ = (2*R*S)/I
Write EOQ
Stop
Algorithm Flowchart
1. Start Start
2. Read R, S, I
3. EOQ = (2*R*S)/I
4. Print EOQ Read R, S, I
5. Stop
EOQ = (2*R*S)/I
Write EOQ
Stop
7|Page Youtube.com/EngineersTutor www.EngineersTutor.com
Q10. Write a program to compute the radius of a circle. Derive your formula from the given equation:
A=πr², then display the output.
Algorithm Flowchart
1. Start
2. Read r Start
3. Calculate radius by
the equation:
r = sqrt(A/pi) Read A
4. Write r
5. Stop
r = sqrt(A/pi)
Write r
Stop
8|Page Youtube.com/EngineersTutor www.EngineersTutor.com